remove_post_type_support()
Removes the registered capability from the specified post type.
The capability is registered in the supports parameter of the register_post_type() function.
Usually, the capability is simply responsible for displaying the meta box. But there are other capabilities, for example:
revisions- besides displaying information about revisions in the admin, it determines whether to enable the revision functionality (saving post revisions) for the post type.comments- determines whether to display the number of comments on the post editing page.
This function usually needs to be called during the init action. That is, after the post types are registered - added to the global variable $_wp_post_type_features.
Modifies the global variable $_wp_post_type_features.
No Hooks.
Returns
null. Nothing.
Usage
remove_post_type_support( $post_type, $feature );
- $post_type(string) (required)
- The name of the post type from which the capability needs to be removed.
- $feature(string) (required)
The name of the capability to be removed. It can be:
title- title box;editor- content input box;author- author selection box;thumbnail- post thumbnail selection box;excerpt- quote input box;trackbacks- notifications box;custom-fields- custom fields setup box;comments- comments box;revisions- revisions box (not displayed until there are revisions);page-attributes- attributes box for static pages (template and hierarchical relationship of posts, hierarchy must be enabled). Can be used instead.post-formats– post formats box, if they are enabled in the theme.
Examples
#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' );
} #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' );
} #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.
}
}
}
Notes
- Global. Array. $_wp_post_type_features
Changelog
| Since 3.0.0 | Introduced. |
remove_post_type_support() remove post type support code WP 6.8.3
function remove_post_type_support( $post_type, $feature ) {
global $_wp_post_type_features;
unset( $_wp_post_type_features[ $post_type ][ $feature ] );
}