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

Now, when you add or edit a particular post within your desired post type, there are more screen options as well. Although, these Screen Options are showing/hiding meta boxes. I would like to be able to programmatically obtain a list of all of these registered Screen Options of meta boxes, so that I can again check if a certain array of Screen Options exist, and if they do, I plan on removing them programmatically.

WordPress - Screen Options - Add or Edit Post - Meta Boxes
Click Here For Full Size Screenshot

Question
How can I programmatically obtain a list of all registered Screen Options (meta boxes) on post types, where you want to add or edit a particular post within your desired post type.

Ultimately, the goal here is to remove these options and not simply just disable them. I’m looking to do something along the lines of what I have accomplished for removing unnecessary dashboard meta boxes.

2 s
2

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