Out-of-the-box, the meta boxes that WordPress displays on the dashboard aren’t exactly overkill. I mean, if you’re a blogger, then I think the chances are strong that you’ll need:

  • Publish
  • Categories
  • Tags
  • Comments
  • And maybe the Excerpt feature (depending on your theme)

But if you’re building a solution for someone else where that information is irrelevant, wouldn’t it be worth removing the WordPress meta boxes to make the dashboard a little bit cleaner with less irrelevant options?

Remove WordPress Meta Boxes

When removing WordPress meta boxes, I’ve seen it done in a number of different ways two of which are often done via JavaScript. Though this is functional for many, client-side solutions aren’t always great especially as it relates to accessibility.

WordPress Meta Boxes

On top of that, hiding things via JavaScript is kind of a hack – the visibility of elements should often be set in terms of CSS and it will likely cause a little bit of a flicker when the element is being hidden while the DOM loads.

Anyway, the two ways I’ve often seen it done is when:

  1. Developers look for the check boxes under the Screen Options and then trigger the click event.
  2. Developers sniff out the meta boxes ID and then use jQuery’s hide() method to hide the meta boxes from the page.

Sure, these work, but you’re still faced with the challenges of accessibility and with the fact that you’re modifying something that should probably be done via CSS.

Unless a hook exists.

And that’s really the mentality that we, as WordPress developers, should have whenever we’re attempting to introduce, remove, or modify anything as it relates to WordPress both in the dashboard and on the front-end.

Specifically, we need to ask ourselves:

Given what I need to do, is there a hook that makes this available?

And this is this case (and many, many cases), there is. We can take advantage of the default_hidden_meta_boxes hook. Though I was unable to find a Codex page for this particular hook, you can see it in core’s source code.

Using The Hook

The function accepts two arguments:

  1. An array of meta boxes that should be hidden
  2. The current screen being displayed

This allows us to modify the existing array of hidden meta boxes (or create our own) and only trigger it on specific screen’s, as well.

So let’s say that we have a custom post type called acme_post_type and we want to hide the Categories, Author, Post Excerpt, and Slug meta box.

To do this, we can define the following function:

First, the code checks to see if we’re on the screen for the custom post type. If so, then we define a new array that includes the IDs of the meta boxes that we want to hide. After that, we the array to WordPress and the end-result of the function will be that the specified meta boxes will be hidden from view.

In terms of getting the ID of the meta boxes that you want to hide, you can use the Developer Tools of your preferred browser to inspect the elements on the page. You can also use a reference on this Codex page.

Category:
Notes
Tags:

Join the conversation! 8 Comments

  1. I love you man! I have been doing a lot of CPT’s with Advanced Custom Fields and I don’t need any of the SEO or other “post” related meta-boxes on my screens.

    I was about to start doing research on this when providence shined and I saw a link to your article in “The Daily Bolt” e-newsletter.

  2. ps. If anyone uses this to create a plugin with a settings page that allows you to set the hidden metaboxes per post-type, please post a link to the plugin and the donate button for it.

  3. Is there a way to use it in a plugin?

    I have a plugin that sets up a CPT and CT but i would like to get rid of Yoast SEO metabox and WPML metabox :)

    • Yep – to add this in a plugin, you’d define the usual header so that WordPress would recognize it as a plugin, then place the code in a function that would be fired whenever the plugin is activated.

  4. Hi Tom,

    Thank you for your valuable info. These are really great tips. This was a good chance for others to share their experiences. Thank you for sharing these kind useful tips for others. Keep posting.

  5. How to hide custom meta box for a specific categories..

    For example if i select IT job category then a specific meta box will shown and others meta box will be hide.

    • I can’t really walk through a tutorial like this on this particular site. Normally, I’d recommend having a CPT for and then have the meta box available only on the CPTs that are allowed.

      If you want to do it via category, you’ll likely need to use JavaScript.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.