remove_meta_box( string $id, string|array|WP_Screen $screen, string $context )

Removes a meta box from one or more screens.

Parameters

$idstringrequired
Meta box ID (used in the 'id' attribute for the meta box).
$screenstring|array|WP_Screenrequired
The screen or screens on which the meta box is shown (such as a post type, 'link', or 'comment'). Accepts a single screen ID, WP_Screen object, or array of screen IDs.
$contextstringrequired
The context within the screen where the box is set to display.
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.

More Information

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.

Source

function remove_meta_box( $id, $screen, $context ) {
	global $wp_meta_boxes;

	if ( empty( $screen ) ) {
		$screen = get_current_screen();
	} elseif ( is_string( $screen ) ) {
		$screen = convert_to_screen( $screen );
	} elseif ( is_array( $screen ) ) {
		foreach ( $screen as $single_screen ) {
			remove_meta_box( $id, $single_screen, $context );
		}
	}

	if ( ! isset( $screen->id ) ) {
		return;
	}

	$page = $screen->id;

	if ( ! isset( $wp_meta_boxes ) ) {
		$wp_meta_boxes = array();
	}
	if ( ! isset( $wp_meta_boxes[ $page ] ) ) {
		$wp_meta_boxes[ $page ] = array();
	}
	if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
		$wp_meta_boxes[ $page ][ $context ] = array();
	}

	foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
		$wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false;
	}
}

Changelog

VersionDescription
4.4.0The $screen parameter now accepts an array of screen IDs.
2.6.0Introduced.

User Contributed Notes

  1. Skip to note 16 content

    To remove all the widgets from the dashboard screen, use:

    add_action('wp_dashboard_setup', 'wpdocs_remove_dashboard_widgets');
    
    /**
     * Remove all dashboard widgets
     */
    function wpdocs_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.
    }
  2. Skip to note 17 content

    I was having problems removing the “author” div on a custom post type. The solution was to use a different hook. Instead of using the “admin_menu” hook, the “admin_head” hook worked.

    e.g.

    <?php 
    add_action( 'admin_head' , 'wpdocs_remove_post_custom_fields' );
     
    /**
     * Remove Custom Fields meta box
     */
    function wpdocs_remove_post_custom_fields() {
        remove_meta_box( 'authordiv' , 'my-cpt' , 'normal' ); 
    }
    ?>
  3. Skip to note 18 content

    Here is an example that removes the Custom Fields box from the Post edit screen.

    <?php 
    add_action( 'admin_menu' , 'wpdocs_remove_post_custom_fields' );
    
    /**
     * Remove Custom Fields meta box
     */
    function wpdocs_remove_post_custom_fields() {
    	remove_meta_box( 'postcustom' , 'post' , 'normal' ); 
    }
    ?>
  4. Skip to note 19 content

    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:

    add_action( 'do_meta_boxes', 'wpdocs_remove_plugin_metaboxes' );
    
    /**
     * Remove Editorial Flow meta box for users that cannot delete pages 
     */
    function wpdocs_remove_plugin_metaboxes(){
        if ( ! current_user_can( 'delete_others_pages' ) ) { // Only run if the user is an Author or lower.
            remove_meta_box( 'ef_editorial_meta', 'post', 'side' ); // Remove Edit Flow Editorial Metadata
        }
    }
  5. Skip to note 21 content

    Gutenberg editor does not recognize the old way of removing panels. If you like me have custom taxonomies you should remove them with JavaScript.

    add_action( 'admin_enqueue_scripts', 'wpdocs_my_admin_scripts' );
     
    function wpdocs_my_admin_scripts( $hook ) {
        wp_enqueue_script( 'wpdocs-my-editor-script', 'my-editor-script.js' );
    
        $data = array(
            'hook' => $hook
        );
    
        wp_localize_script( 'wpdocs-my-editor-script', 'my_editor_script', $data );
    }

    Then your script…

    window.addEventListener( 'load', () => {
        if ( [ 'post.php', 'post-new.php' ].indexOf( my_editor_script.hook ) > -1 ) {
            wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'taxonomy-panel-MY-TAXONOMY-NAME' ) ;
        }    
    } )

    Other panels can be removed also.

  6. Skip to note 22 content

    It’s easier not to show meta boxes for custom taxonomies in the editor by adding:

    'meta_box_cb' => false,

    This is added within register_taxonomy().

    For example:

    function custom_tags(){
    	$singular_name = 'Example';
    	$plural_name = 'Examples';
    	$taxonomy_slug = sanitize_title_with_dashes($singular_name); // Taxonomy key, must not exceed 32 characters.
    	$category_taxonomy = false; // False for Tags, True for Categories
    	$post_type = 'custom_post_type'; // Object type or array of object types with which the taxonomy should be associated.
    	$labels = array(
    		'name' => _x( $plural_name, 'Taxonomy Plural Name' ),
    		'singular_name' => _x( $singular_name, 'Taxonomy Singular Name' ),
    		'search_items' =>  __( 'Search ' . $plural_name ),
    		'popular_items' => __( 'Popular ' . $plural_name ),
    		'all_items' => __( 'All ' . $plural_name ),
    		'parent_item' => null,
    		'parent_item_colon' => null,
    		'edit_item' => __( 'Edit ' . $singular_name ), 
    		'update_item' => __( 'Update ' . $singular_name ),
    		'add_new_item' => __( 'Add New ' . $singular_name ),
    		'new_item_name' => __( 'New ' . $singular_name . ' Name' ),
    		'separate_items_with_commas' => __( 'Separate ' . $plural_name . ' With Commas' ),
    		'add_or_remove_items' => __( 'Add or Remove ' . $plural_name ),
    		'choose_from_most_used' => __( 'Choose From the Most Used ' . $plural_name ),
    		'menu_name' => __( $plural_name ),
      	);
    	register_taxonomy(
    		$taxonomy_slug,
    		$post_type,
    		array(
    			'hierarchical' => $category_taxonomy,
    			'labels' => $labels,
    			'show_ui' => true,
    			'show_in_rest' => true,
    			'show_admin_column' => true,
    			'meta_box_cb' => false,
    			'update_count_callback' => '_update_post_term_count',
    			'query_var' => true,
    			'rewrite' => array( 'slug' => $taxonomy_slug ),
    		)
    	);
    }
    add_action( 'init', 'custom_tags' );
  7. Skip to note 24 content

    Here is another example that removes the Excerpt meta box from the Page edit screen,

    <?php 
    add_action( 'admin_menu' , 'wpdocs_remove_page_excerpt_field' );
    
    /**
     * Remove the Excerpt meta box
     */
    function wpdocs_remove_page_excerpt_field() {
    	remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); 
    }
    ?>
  8. Skip to note 25 content

    If you want to remove a custom taxonomy box from a custom post type edit screen, you can use this:

    add_action( 'admin_menu', 'wpdocs_remove_custom_taxonomy' );
    
    /**
     * Remove the genre taxonomy box from the movie edit screen
     */
    function wpdocs_remove_custom_taxonomy()
    {
    	$custom_taxonomy_slug = 'genre';
    	$custom_post_type = 'movies';
    	
    	remove_meta_box('tagsdiv-'.$custom_taxonomy_slug, $custom_post_type, 'side' );
    }
  9. Skip to note 26 content

    This example removes certain meta boxes from the post edit screens of both the Post and Link post types for non-administrators.

    if ( is_admin() ) {
    	add_action( 'admin_menu', 'wpdocs_remove_meta_boxes' );
    }
    
    /**
     * Remove meta boxes from the post edit screens
     */
    function wpdocs_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' );
    	}
    }
  10. Skip to note 27 content

    This example removes the Comments, Author and Comments Status meta boxes from the Page edit screen,

    <?php 
    add_action( 'admin_menu' , 'wpdocs_remove_page_fields' );
    
    /**
     * Remove meta boxes from page screen
     */
    function wpdocs_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 
    }
    ?>
  11. Skip to note 29 content

    In order to remove a widget from the Network Dashboard, you must use wp_network_dashboard_setup hook.

    /**
     * Remove the WordPress News & Events widget from Network Dashboard
     */
    function wpdocs_remove_network_dashboard_widgets() {
    	remove_meta_box( 'dashboard_primary', 'dashboard-network', 'side' );
    }
    add_action( 'wp_network_dashboard_setup', 'wpdocs_remove_network_dashboard_widgets' );
  12. Skip to note 30 content

    If you want to remove all default metaboxes created for your custom taxonomies, but don’t want to set the ‘show_ui’ => false in the registration of the taxonomy (because it would remove it from the menu), here’s a function for that:

    function mytheme_remove_all_metaboxes() {
    	$args = array(
    	   'public'   => true,
    	   '_builtin' => false
    	);
    	$post_types = get_post_types($args);
    	foreach ($post_types as $i => $post_type) {
      		$taxonomy_objects = get_object_taxonomies( $post_type, 'object' );
      		foreach ($taxonomy_objects as $j => $tax_obj) {
      			if($tax_obj->hierarchical){
      				$div_id = $tax_obj->name . 'div';
      			} else {
      				$div_id = 'tagsdiv-' . $tax_obj->name;
      			}
    			remove_meta_box($div_id, $post_type, 'side');
      		}
    	}
    }
    add_action('admin_menu', 'mytheme_remove_all_metaboxes', 999);

You must log in before being able to contribute a note or feedback.