WordPress How-to: Remove Meta Boxes from Custom Post Types

- Code Snippets, Quick Tips, WordPress

Have you ever wanted to remove something from the post edit view in the WordPress admin? Perhaps you don’t use specific features and would just like to clean up your admin interface, or maybe you’d like to prevent certain user roles from accessing them. Below I’ve outlined 3 options to do just this.

 

OPTION #1: Adminimize

For those that don’t want to deal with code, this plugin is a powerful tool to fully customize your admin experience. Combined with another plugin User Role Editor you can create unique viewing permissions for all user roles you create down to a granular level. We use Adminimize often when building client websites to limit access to core configuration. This still gives them full control of their website without feeling bombarded by options in the admin panel.

 


 

OPTION #2: Screen Options

A nice built in feature of WordPress is the Screen Options panel. A quick way to clean up the edit area of of your posts, pages, and custom post types. Simply go to the edit screen of any post, page, or custom post-type and you will see the screen options in the top right. Un-check anything you don’t want to display. The one downside of this method is it must be done per user account, and the user can still easily re-enable anything by going back into the screen options.

 


 

OPTION #3: PHP Function

My personal favorite to keep the amount of plugins to a minimum is to add a simple code snippet to the theme’s function.php file. See this example below for removing categories from The Events Calendar plugin post-type:

function remove_event_cats() {
remove_event_cats( 'tribe_events_catdiv' , 'tribe_events' , 'side' );
}
add_action( 'admin_menu' , 'remove_event_cats' );

There are 3 main components to this function:

  • tribe_events_catdiv – this is the ID of the categories meta box for events
  • tribe_events – this is the slug for the post type.
  • side – this specifies the specific location, in this case the right sidebar

Simply modify the variables within the code to your needs to remove any meta box for any post type.

 

 

The one downside of utilizing the functions.php file is it is dependent upon the current active theme. If you we’re to switch themes you would need to reapply this code.

 

I hope this helps! If you need any WordPress assistance you can always Open a Support Ticket with us or send an email to [email protected].