remove_post_type_support()WP 3.0.0

Remove support for a feature from a post type.

1 time — 0.000021 sec (very fast) | 50000 times — 0.03 sec (speed of light)

No Hooks.

Return

null. Nothing (null).

Usage

remove_post_type_support( $post_type, $feature );
$post_type(string) (required)
The post type for which to remove the feature.
$feature(string) (required)
The feature being removed.

Examples

0

#1 Remove "Quote" metabox on post edit page of custom post type "xxx"

add_action( 'init', 'my_remove_post_excerpt_feature' );

function my_remove_post_excerpt_feature() {

	remove_post_type_support( 'xxx', 'excerpt' );
}
0

#2 Remove support for post formats

add_action( 'init', 'my_remove_post_formats_support', 10 );

function my_remove_post_formats_support() {
	remove_post_type_support( 'post', 'post-formats' );
}
0

#3 Hide page visual editor if certain template is selected:

add_action( 'init', 'remove_editor_init' );

function remove_editor_init() {

	// If not in the admin, return.
	if ( ! is_admin() ) {
	   return;
	}

	// Get the post ID on edit post with filter_input super global inspection.
	$current_post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
	// Get the post ID on update post with filter_input super global inspection.
	$update_post_id = filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT );

	// Check to see if the post ID is set, else return.
	if ( isset( $current_post_id ) ) {
	   $post_id = absint( $current_post_id );
	} else if ( isset( $update_post_id ) ) {
	   $post_id = absint( $update_post_id );
	} else {
	   return;
	}

	// Don't do anything unless there is a post_id.
	if ( isset( $post_id ) ) {
	   // Get the template of the current post.
	   $template_file = get_post_meta( $post_id, '_wp_page_template', true );

	   // Example of removing page editor for page-your-template.php template.
	   if (  'page-your-template.php' === $template_file ) {
			remove_post_type_support( 'page', 'editor' );
			// Other features can also be removed in addition to the editor.
			// See: https://codex.wordpress.org/Function_Reference/remove_post_type_support.
	   }
	}
}

Credit: https://wordpress.stackexchange.com/a/91644/138483

Notes

  • Global. Array. $_wp_post_type_features

Changelog

Since 3.0.0 Introduced.

remove_post_type_support() code WP 6.5.2

function remove_post_type_support( $post_type, $feature ) {
	global $_wp_post_type_features;

	unset( $_wp_post_type_features[ $post_type ][ $feature ] );
}