One of my growing WordPress-related hobbies is disabling features of the platform. WordPress has a ton of great features in the admin, but for my personal blog and some client sites, the UI gets too messy sometimes.
This week, I’ve been reconfiguring a lot stuff on the backend of this site. One of the things I done was disable quite a few meta boxes to make a cleaner post editing screen. Sure, I could simply click the “Screen Options” tab and hide the meta boxes. However, I have no need for these meta boxes at all. I just wanted them gone.
In light of a WPTavern discussion and the reconfiguring I’ve been doing, I wanted to share a tutorial with you. This tutorial will walk you through the simple steps of disabling meta boxes for the post editing screen. Some possible uses for this functionality are:
- Uncluttering your personal site’s editing screen.
- Disabling stuff for clients that they’ll never need.
- Replacing a meta box with a custom meta box you’ve created.
- Removing meta boxes added by custom post types from plugins.
There are several methods for disabling some of the meta boxes, but for the purposes of this tutorial, we’ll stick with a single method.
The remove_meta_box() function
Before removing any meta boxes, you need to learn how the remove_meta_box() function works. It’s a function for (you guessed it), removing meta boxes.
remove_meta_box( $id, $page, $context );
Each of the three parameters are required to disable a meta box.
$id
– The ID used to register the meta box.$page
– The page the meta box is displayed on. For posts, this is the name of the post type (e.g.,post
,page
).$context
– The area of the screen the meta box is displayed on. For posts, the three possibilities arenormal
,advanced
, andside
.
If you wanted to remove the “comments” meta box from the post editor, the use of this function would look like the following:
remove_meta_box( 'commentsdiv', 'post', 'normal' );
How to remove meta boxes
From this point forward, your code will go either in your theme’s functions.php
file or a custom plugin file.
Let’s look at the code from the previous section where we created the code to remove the comments meta box. To put this to use, we need to create a new function and execute it on the add_meta_boxes
action hook.
add_action( 'add_meta_boxes', 'my_remove_post_meta_boxes' );
function my_remove_post_meta_boxes() {
remove_meta_box( 'commentsdiv', 'post', 'normal' );
/* Additional calls to remove_meta_box() go here. */
}
All you need to do is drop any calls to the remove_meta_box()
function inside your custom my_remove_post_meta_boxes()
function.
I would’ve recommended the admin_menu
hook to remove meta boxes, which is what many developers seem to use and is the example hook provided in the WordPress Codex. However, not all meta boxes can be removed when using this hook. The featured image meta box is one such meta box.
What meta boxes you can remove
Now that you know how to remove meta boxes, you might be interested in removing something other than the comments meta box as I’ve used in this tutorial. The following is a list the meta boxes you can remove from the post (or any custom post type) editing screen.
submitdiv
– The “Publish” box that allows you to set several things.commentsdiv
– Displays comments made on the post.trackbacksdiv
– Displays an input box for sending trackbacks.commentstatusdiv
– Allows you to enable/disable comments and pings for the post.revisionsdiv
– Displays post revision links.authordiv
– Displays a select box to choose a post author.postexcerpt
– Creates a textarea for writing a custom excerpt.formatdiv
– Allows the user to select a post format.pageparentdiv
– The “Attributes” box for choosing a page parent and template.postimagediv
– Displays the featured image box.slugdiv
– Displays an additional post slug box.tagsdiv-post_tag
– Displays the post tags meta box for selecting tags.categorydiv
– Displays the categories meta box for selecting categories.tagsdiv-{$taxonomy}
– Lets you choose terms for a non-hierarchical taxonomy (use the taxonomy name).{$taxonomy}div
– Allows you to set terms for a hierarchical taxonomy (use the taxonomy name).
Example removing all meta boxes
Since removing each meta box will be slightly different because of the $context
parameter discussed earlier, I’ve decided to create the code to remove all meta boxes on the post editing screen. You can copy the following code and pick and choose which parts you need.
Also, this is just for the post
post type. If you want to try it out with other post types, change post
to the name of your preferred post type in the call to remove_meta_box()
.
add_action( 'add_meta_boxes', 'my_remove_post_meta_boxes' );
function my_remove_post_meta_boxes() {
/* Publish meta box. */
remove_meta_box( 'submitdiv', 'post', 'normal' );
/* Comments meta box. */
remove_meta_box( 'commentsdiv', 'post', 'normal' );
/* Revisions meta box. */
remove_meta_box( 'revisionsdiv', 'post', 'normal' );
/* Author meta box. */
remove_meta_box( 'authordiv', 'post', 'normal' );
/* Slug meta box. */
remove_meta_box( 'slugdiv', 'post', 'normal' );
/* Post tags meta box. */
remove_meta_box( 'tagsdiv-post_tag', 'post', 'side' );
/* Category meta box. */
remove_meta_box( 'categorydiv', 'post', 'side' );
/* Excerpt meta box. */
remove_meta_box( 'postexcerpt', 'post', 'normal' );
/* Post format meta box. */
remove_meta_box( 'formatdiv', 'post', 'normal' );
/* Trackbacks meta box. */
remove_meta_box( 'trackbacksdiv', 'post', 'normal' );
/* Custom fields meta box. */
remove_meta_box( 'postcustom', 'post', 'normal' );
/* Comment status meta box. */
remove_meta_box( 'commentstatusdiv', 'post', 'normal' );
/* Featured image meta box. */
remove_meta_box( 'postimagediv', 'post', 'side' );
/* Page attributes meta box. */
remove_meta_box( 'pageparentdiv', 'page', 'side' );
}
I hope you find this tutorial useful in your projects. Let me know if you do anything interesting with it.
I think you may have missed something…
I may have missed something, but I don’t think so. I hope you decide to go ahead and write that part, because it’s something I’ve really been wanting to do!
Creating and using custom meta boxes is a bit outside the scope of this tutorial. However, I do have a tutorial I’ve been wanting to write for a while that covers how to do this.
I’m not upset that you’re not writing about it, I was just quoting what you said you’d teach in the top of the article.
I didn’t say that I’d teach that. I said, “Some possible uses…” 🙂
Ah, my bad. 🙂
PLEEEEAAAAASE write that tutorial!
I can’t find anything good in many days of searching and I have a site for a client that I need to figure out how to get a theme’s meta-boxes to show in a custom post type’s edit page ASAP… grrrr… Thanks in advance!
If you don’t want to use a plugin like More Fields or go from scratch, I’d look into
https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
🙂
So if this “removes” the meta boxes, will this also remove them from the screen options tab? If so, is there a function to set which are disabled by default (as they’ve done in 3.1) but still give the user the option to turn them back on?
Screen options deal with user meta, which is another tutorial altogether. Hidden meta boxes for the post screen are saved as an array for the
metaboxhidden_post
meta key. You might want to look into the update_user_meta() function.Awesome! I’ve been thinking about starting to do this now that my blog has multiple contributors.
So if I put this code inside an if statement that determines if the person is, say, an editor or a contributor, it will only happen for that person? I’m not sure if if statements work in the functions.php
You can use if statements in your
functions.php
file. There’s no problem with that. Just make sure you use your checks within the function so that all WordPress functions are loaded before you start using them.Thanks for yet another top quality post Justin. If you don’t need it then I agree to removing it, which before now I have always hidden just using the Screen Options, I might just have to reconsider now! 😉
Certainly are a few I’d love to get rid of, they must of had a purpose in WordPress at some stage, now you wonder why it’s still there? — Take the
slugdiv
as an example, you can change the slug for the post right underneath the title now!I could be wrong, but I think
slugdiv
might be useful for folks with JavaScript disabled in their browser. I believe the one under the title is generated via JavaScript. I have no need for this meta box, so it was one of the first to go.The Screen Options tab can actually get a bit cluttered too for posts (especially if you have plugins that add meta boxes), which is one reason I started getting rid of stuff.
As always Justin a good tutorial .
– the next logical step is how to preset this for one’s members.
I had taken this one step further and writen a plugin so that one can logon as a ‘template’ user , set up the wp environment the way you want all users of a role to be and then click a few buttons to choose some roles .
Then all users of that role will be setup to have those same settings. Also any new users of that role will have those settings.
It’s quiet sweet they way it works becuase you can start a user with the simplest setup, as they learn more, all the screen options, columns etc are still there and they can tick them back on for themselves if they need to.
Best of both worlds.
Also thanks for your input in the pro wordpress plugin book – looking at the table of contents, I thought oh – yeah – I know all that. Decided to get the e-book anyway, and yes they say wisdom is knowing that one may not know everything (or something like that), so I must be wise as there were a few nuggets that I gleaned. 🙂
Yeah, I’ve had to do a custom plugin for a client once to preset some of this stuff. WordPress is so flexible that you have several different options.
I’d say 99% of all developers will learn at least something from Pro WP Plugin Development. Half the battle (and half the fun) of writing my chapters was learning new things about WordPress. WordPress has many little-known and sparsely-documented features that we covered.
Thanks for getting the book. 🙂
I bought your book 😉
Thanks. I hope you enjoy reading it. 🙂
Great post justin. Hey, I bought your book too, it got to say, it is one of the best I’ve seen on Amazon.
Thanks. I’m glad you like the book.
Awesome tips to clean up WP admin. It seems that with every new version of WP there is more and more junk on the admin screens.
I just use the options (from the tab at the top of the screen on the right hand side) to choose which boxes I show. Seems easier?
Ben.
See the explanation in the first few paragraphs of the article above.
Thanks man 🙂 !
But I still have a problem… How can I remove the title div meta box :/ ? I don’t want to let the user the capabilty to change it…
Thanks
Add this to functions.php
Should work!
Thank you for the post. It is a little sophisticated for me at this point (skill-level), but I understand the concept and appreciate the time it took to share this info.
great post, thanks.
i’m wondering if it’s possible to remove meta boxes from custom taxonomy admin pages. for example i’d like to remove the slug and description from this custom taxonomy. http://cl.ly/7dYN
any ideas?
Am using this method on a site and wanted to include the featured image div – but it won’t work…
This is the code:
Where am i messed up?
There’s a yellow box mid-way through the article where Justin explains that not all boxes can be removed with the ‘admin-menu’ hook. Instead, it needs to use the ‘add_meta_boxes’ hook instead.
It turns out that ‘Featured Image’ is one of them…and from my own exploration, so is Category.
Thanks justin. as useall you make it simple to understand
Needed a way to remove that custom feilds for a while but was lazy
Searching the codex.. 🙂
How would I remove metaboxes from a specific post or page? Instead of affecting all posts or pages.
Thanks it helped me a lot. Used to remove taxonomy boxes form CPT page. 🙂
I see no button for tweeting this post… 🙁
Can you specify whether a meta box can be minimized or not? I know that the wpalchemy library allows you switch off the ability to minimize a meta box but I can’t seem to find a function in Wordpress’ codex.
Once again, the answer to my question is right here. I’ve taken to automatically opening your site in another window whenever I go to work on WordPress!
You Rock, Justin!
I’ve no experience of PHP, recently came from desktop development to web developement. I’m much annoyed by the problem this cluttered UI. I would like to have a box with autohide features. Is it possible?
Justin – is there a clean way to deselect the Members plugin Content Permissions metabox in the screen options? Or even better, a way to remove it altogether for a custom post type while displaying it for pages?
I know this is 4 years ago but if anyone else is looking for this answer the code you need is
I just had a go of this, trying to get rid of the categories meta-box in the right sidebar and had to substitute ‘categoriesdiv’ with ‘tagsdiv-categories’.
As far as I can tell you can always check the meta-box you wish to eliminate using developer tools in your browser, check the id attribute and use that as the first argument for remove_meta_box.
I could be wrong but from my experience it seems these id values change from version to version.
The only metabox that nobody ever told me how to remove is the main content metabox. I tried everything but nothing ever worked for me (apart from the plugin advanced custom fields which has an option for removing metaboxes but even looking at its source code i wasn’t able to find out how it does it, my bad).
nevermind! i found a way!
as the content is not a metabox the code to remove is different so i had to use
:)))
Does all this code still work with WordPress 4,1.1? I’m trying to remove the slug box, and it won’t go away. I’ve tried
remove_meta_box( 'slugdiv', 'post', 'normal' );
and
remove_meta_box( 'edit-slug-box', 'post', 'normal' );
and neither work. I’ve tried hooking into
admin_menu
andadd_meta_boxes
, and no success 🙁It should work. You’re not looking at the edit permalink field below the title are you? That’s a different thing.
Um, the’re not?
My bad. I’ve been looking at the “permalink” field. I guess I got the two concepts mixed up…
Is there a way to remove “premalink”?