remove_meta_box()WP 2.6.0

Deletes meta-boxes (additional blocks in the admin panel) on the post, page, and custom post type editing screens.

The function should be called after the meta-boxes have been added. Meta-boxes are usually added on the add_meta_boxes hook. Before the add_meta_boxes hook, only the meta-boxes of WordPress itself are registered; custom meta-boxes are registered on this hook.

Meta-boxes are added by the add_meta_box() function.

No Hooks.

Returns

null. Returns nothing.

Usage

remove_meta_box( $id, $screen, $context );
$id(string) (required)

id attribute of the HTML tag, Block container. Basic WordPress Blocks have the following ids:

  • authordiv - author settings block;
  • categorydiv - categories;
  • tagsdiv-post_tag - tags;
  • commentstatusdiv - comment status block;
  • commentsdiv - comments block;
  • formatdiv - post formats;
  • pageparentdiv - attributes of permanent pages;
  • postcustom - custom fields block;
  • postexcerpt - excerpt block;
  • postimagediv - post image block;
  • revisionsdiv - revisions block;
  • slugdiv - alternative title block (slug);
  • trackbacksdiv - notifications block;
  • ...
$screen(string/array/WP_Screen) (required)

The name of the screen where the block is removed. See get_current_screen(). For example, it can be:

  • For post types: post, page, link, attachment or custom_post_type
  • Or for other admin pages: link, comment.
  • Multiple types can be specified in an array: array('post', 'page'). Since version 4.4.
  • null - will be removed on any screen (on the current screen).
$context(string) (required)
The place where the Block is displayed. Can be: normal, advanced, side.

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 Global meta box state.

Changelog

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

remove_meta_box() code WP 6.9

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