remove_meta_box()WP 2.6.0

Removes a meta box from one or more screens.

No Hooks.

Return

null. Nothing.

Usage

remove_meta_box( $id, $screen, $context );
$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.

Examples

0

#1 Removing the metabox

Example of deleting a Block of custom fields on the post editing page:

add_action( 'add_meta_boxes' , 'remove_post_custom_fields', 99 );

function remove_post_custom_fields(){
	remove_meta_box( 'postcustom' , 'post' , 'normal' );
}
0

#2 Deleting a "quote" metabox

Example of removing the Citation Block from the edit pages of "static pages":

add_action( 'add_meta_boxes' , 'remove_page_excerpt_field', 99 );

function remove_page_excerpt_field() {
	remove_meta_box( 'postexcerpt' , 'page' , 'normal' );
}
0

#3 Deleting comments

This example, removes the Comments, Author, and Comment Status blocks from the edit page of the "static pages":

add_action( 'add_meta_boxes' , 'remove_page_fields', 99 );

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

#4 Deleting custom taxonomies

If you want to remove the Custom Taxonomy Block (created by the user), on the custom post edit page, use following code:

add_action( 'add_meta_boxes' , 'remove_custom_taxonomy', 99 );

function remove_custom_taxonomy(){
	remove_meta_box( 'tagsdiv-custom_taxonomy_slug', 'name_type_post', 'side' );
}
0

#5 This way you can even delete the Publication Block:

add_action( 'add_meta_boxes' , 'remove_publish_box', 99 );

function remove_publish_box(){
	remove_meta_box( 'submitdiv', 'custom_post_slug', 'side' );
}
0

#6 Remove the 'commentsdiv' metablock if the post type does not support 'comments'.

In WordPress, this metabox appears when the post type supports 'comments' or if the post has comments or if comments are open.

But if no 'comments' support is specified for the post type, the metabox still appears and the post author can edit comments. Sometimes this is not necessary and in those cases the post comments metabox 'commentsdiv', can be removed as follows:

// remove the 'commentsdiv' metablock if the post type does not support 'comments'.
// odd that WP does not do it that way!
//do_action( 'add_meta_boxes', $post_type, $post );
add_action( 'add_meta_boxes', function( $post_type ) {

	if( ! post_type_supports( $post_type, 'comments' ) )
		remove_meta_box( 'commentsdiv', $post_type, 'normal' ); //removes comments
} );

Notes

  • Global. Array. $wp_meta_boxes

Changelog

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

Code of remove_meta_box() WP 5.9.3

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