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

Removes a meta box from one or more screens.


Description Description


Parameters Parameters

$id

(string) (Required) Meta box ID (used in the 'id' attribute for the meta box).

$screen

(string|array|WP_Screen) (Required) 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.

$context

(string) (Required) 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.


Top ↑

Source Source

File: wp-admin/includes/template.php

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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 The $screen parameter now accepts an array of screen IDs.
2.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    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
        }
    }
    
    
  2. Skip to note content
    Contributed by Codex

    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.
    }
    
    
  3. Skip to note content
    Contributed by Codex

    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' );
    	}
    }
    
  4. Skip to note content
    Contributed by Codex

    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 
    }
    ?>
    
    
  5. Skip to note content
    Contributed by Codex

    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' );
    }
    
    

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