How to Remove Certain Screen Options and Meta Boxes from add/edit post type?

What you need is in global $wp_meta_boxes indexed by get_current_screen()->id. Removing the screen options will also remove the metaboxes which you can do just before screen options are displayed using the 'in_admin_header' hook.

So let’s assume you want to get rid of the “Send Trackbacks” screen option which you see in this screenshot:

Drop the following class into your theme’s functions.php file or in a plugin you might be building and the code will remove the “Send Trackbacks” screen option (and it’s associated metabox, which is also what you wanted, right?):

class Michael_Ecklunds_Admin_Customizer {
  function __construct() {
    add_action( 'in_admin_header', array( $this, 'in_admin_header' ) );
  }
  function in_admin_header() {
    global $wp_meta_boxes;
    unset( $wp_meta_boxes[get_current_screen()->id]['normal']['core']['trackbacksdiv'] );
  }
}
new Michael_Ecklunds_Admin_Customizer();

And here’s what it looks like after added the above code to a WordPress 3.4 site:

Using the Zend debugger within PhpStorm here is the inspection of $wp_meta_boxes[get_current_screen()->id] so you can see what values a default installation of WordPress 3.4 has in the Post edit screen (I’ve circled the array indexes I referenced in my example, i.e. $wp_meta_boxes[get_current_screen()->id]['normal']['core']['trackbacksdiv']:

Hopefully this is what you were looking for?

Leave a Comment

tech