Are you looking for a way to remove meta boxes from the post and page editors? This snippet will remove all of the meta boxes from the post and page editors.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin. Optionally comment out the lines for the meta boxes that you would like to keep.
function remove_meta_boxes() { # Removes meta from Posts # remove_meta_box('postexcerpt','post','normal' ); remove_meta_box('postcustom','post','normal'); remove_meta_box('trackbacksdiv','post','normal'); remove_meta_box('commentstatusdiv','post','normal'); remove_meta_box('commentsdiv','post','normal'); # Removes meta from pages # remove_meta_box('postexcerpt','page','normal'); // optionally use this if page excerpts are enabled remove_meta_box('postcustom','page','normal'); remove_meta_box('trackbacksdiv','page','normal'); remove_meta_box('commentstatusdiv','page','normal'); remove_meta_box('commentsdiv','page','normal'); } add_action('admin_init','remove_meta_boxes');
To only remove one metabox, use this code. For example, this snippet will removes the Excerpt metabox from the post editor.
function remove_default_excerpt_metabox() { remove_meta_box( 'postexcerpt','post','normal' ); } add_action('admin_menu','remove_excerpt_metabox');
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 7 Best Drag and Drop WordPress Page Builders Compared.
Awesome! Just what I was looking for. Thanks!
WordPress 5.1 Support.
add_action( 'admin_init', 'post_type_support_init' );
function post_type_support_init() {
remove_post_type_support( 'page', 'comments' );
remove_post_type_support( 'post', 'excerpt' );
remove_post_type_support( 'post', 'author' );
remove_post_type_support( 'post', 'trackbacks' );
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'post', 'revisions' );
remove_post_type_support( 'post', 'post-formats' );
}
Reference: https://codex.wordpress.org/Function_Reference/remove_post_type_support
I tried to remove Page Attributes with this code but is not working. Any help please?
With ‘page’, ‘comments’ is working fine (using Gutenberg editor)
remove_post_type_support( ‘page’, ‘page-attributes’ );
You may want to check out: https://developer.wordpress.org/reference/functions/remove_post_type_support/