Languages: English • (Add your language)
Removes a meta box or any other element from a particular post edit screen of a given post type. It can be also used to remove a widget from the dashboard screen.
<?php remove_meta_box( $id, $page, $context ); ?>
The context within the screen where the boxes should display. Available contexts vary from screen to screen. Post edit screen contexts include 'normal', 'side', and 'advanced'. Comments screen contexts include 'normal' and 'side'. Menus meta boxes (accordion sections) all use the 'side' context. Global default is 'advanced'.
None.
This example removes certain meta boxes from the post edit screens of both the Post and Link post types for non-administrators.
function my_remove_meta_boxes() { if ( ! current_user_can( 'manage_options' ) ) { remove_meta_box( 'linktargetdiv', 'link', 'normal' ); remove_meta_box( 'linkxfndiv', 'link', 'normal' ); remove_meta_box( 'linkadvanceddiv', 'link', 'normal' ); remove_meta_box( 'postexcerpt', 'post', 'normal' ); remove_meta_box( 'trackbacksdiv', 'post', 'normal' ); remove_meta_box( 'postcustom', 'post', 'normal' ); remove_meta_box( 'commentstatusdiv', 'post', 'normal' ); remove_meta_box( 'commentsdiv', 'post', 'normal' ); remove_meta_box( 'revisionsdiv', 'post', 'normal' ); remove_meta_box( 'authordiv', 'post', 'normal' ); remove_meta_box( 'sqpt-meta-tags', 'post', 'normal' ); } } add_action( 'admin_menu', 'my_remove_meta_boxes' );
Here is an example that removes the Custom Fields box from the Post edit screen.
function remove_post_custom_fields() { remove_meta_box( 'postcustom' , 'post' , 'normal' ); } add_action( 'admin_menu' , 'remove_post_custom_fields' );
Here is another example that removes the Excerpt meta box from the Page edit screen,
function remove_page_excerpt_field() { remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); } add_action( 'admin_menu' , 'remove_page_excerpt_field' );
This example removes the Comments, Author and Comments Status meta boxes from the Page edit screen,
function remove_page_fields() { remove_meta_box( 'commentstatusdiv' , 'page' , 'normal' ); //removes comments status remove_meta_box( 'commentsdiv' , 'page' , 'normal' ); //removes comments remove_meta_box( 'authordiv' , 'page' , 'normal' ); //removes author } add_action( 'admin_menu' , 'remove_page_fields' );
If you want to remove a custom taxonomy box from a custom post type edit screen, you can use this:
function remove_custom_taxonomy() { remove_meta_box( $custom_taxonomy_slug.'div', $custom_post_type, 'side' ); // $custom_taxonomy_slug is the slug of your taxonomy, e.g. 'genre' ) // $custom_post_type is the "slug" of your post type, e.g. 'movies' ) } add_action( 'admin_menu', 'remove_custom_taxonomy' );
Even the Publish box can be removed if desired:
function remove_publish_box() { remove_meta_box( 'submitdiv', 'custom_post_id', 'side' ); } add_action( 'admin_menu', 'remove_publish_box' );
To remove all the widgets from the dashboard screen, use:
function remove_dashboard_widgets() { remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); // Right Now remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); // Recent Comments remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); // Incoming Links remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); // Plugins remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); // Quick Press remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); // Recent Drafts remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); // WordPress blog remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' ); // Other WordPress News // use 'dashboard-network' as the second parameter to remove widgets from a network dashboard. } add_action( 'wp_dashboard_setup', 'remove_dashboard_widgets' );
To remove meta boxes created by plugins, 'admin_menu' is fired too early, use 'do_meta_boxes' instead. This is helpful for instances when you want to limit meta boxes by user capability:
function remove_plugin_metaboxes(){ // Only run if the user is an Author or lower. if ( ! current_user_can( 'delete_others_pages' ) ) { // Remove Edit Flow Editorial Metadata remove_meta_box( 'ef_editorial_meta', 'post', 'side' ); } } add_action( 'do_meta_boxes', 'remove_plugin_metaboxes' );
Because you can't remove a meta box until it's been added, it's important to make sure your call to remove_meta_box() happens in the right sequence. Just adding a call to remove_meta_box() bare in your functions.php will probably not do the trick.
The add_meta_boxes action hook is probably a good candidate, since most of your meta boxes are generated on the edit post form page. This hook is called in the wp-admin/edit-form-advanced.php
file after all the meta boxes have been successfully added to the page. This affects all meta boxes (conceivably, other than those that are custom generated by a theme or plugin) that appear on post edit pages (including custom post types edit pages) of the administration back-end.
Since: 2.6
remove_meta_box() is located in wp-admin/includes/template.php