How To Remove WordPress Post Meta Boxes

On the WordPress post screen there are a number of meta boxes which give you options to attach to the post.

For example you can change:

  • Categories
  • Tags
  • Featured Images
  • Excerpt
  • Trackbacks
  • Custom Fields
  • Discussion
  • Slug
  • Author
  • Revisions

If you have a multiple authors on your blog then you might want to disable some of the post meta boxes to anyone other the administrator.

For example you wouldn't want a guest author to disallow the comments or trackbacks on the article, this should be up to the administrators of the site.

To remove a meta box there is a WordPress function remove_meta_box().

<?php remove_meta_box( $id, $page, $context ); ?>

This function takes 3 parameters

  • Meta box ID
  • Post type the box is on
  • Context of the box

The default meta boxes you can remove are:

  • 'commentstatusdiv' - Comments status metabox (discussion).
  • 'commentsdiv' - Comments metabox.
  • 'slugdiv' - Slug metabox.
  • 'revisionsdiv' - Revisions metabox.
  • 'authordiv' - Author metabox.
  • 'postcustom' - Custom fields metabox.
  • 'postexcerpt' - Excerpt metabox.
  • 'trackbacksdiv' - Trackbacks metabox.
  • 'postimagediv' - Featured image metabox.
  • 'formatdiv' - Formats metabox.
  • 'tagsdiv-post_tag' - Tags metabox.
  • 'categorydiv' - Categories metabox.
  • 'pageparentdiv' - Attributes metabox.

If you want to disable these for all users which are not admin user then you can use the following code snippet.

if (is_admin()) :
function remove_post_meta_boxes() {
 if(!current_user_can('administrator')) {
  remove_meta_box('tagsdiv-post_tag', 'post', 'normal');
  remove_meta_box('categorydiv', 'post', 'normal');
  remove_meta_box('postimagediv', 'post', 'normal');
  remove_meta_box('authordiv', 'post', 'normal');
  remove_meta_box('postexcerpt', 'post', 'normal');
  remove_meta_box('trackbacksdiv', 'post', 'normal');
  remove_meta_box('commentstatusdiv', 'post', 'normal');
  remove_meta_box('postcustom', 'post', 'normal');
  remove_meta_box('commentstatusdiv', 'post', 'normal');
  remove_meta_box('commentsdiv', 'post', 'normal');
  remove_meta_box('revisionsdiv', 'post', 'normal');
  remove_meta_box('authordiv', 'post', 'normal');
  remove_meta_box('slugdiv', 'post', 'normal');
 }
}
add_action( 'admin_menu', 'remove_post_meta_boxes' );
endif;

Advertise here

Comment