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.
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; } }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
4.4.0 | The $screen parameter now accepts an array of screen IDs. |
2.6.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
To remove meta boxes created by plugins,
admin_menu
is fired too early, usedo_meta_boxes
instead. This is helpful for instances when you want to limit meta boxes by user capability:Here is an example that removes the Custom Fields box from the Post edit screen.
Here is another example that removes the Excerpt meta box from the Page edit screen,
To remove all the widgets from the dashboard screen, use:
Expand full source codeCollapse full source code
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.
This example removes certain meta boxes from the post edit screens of both the Post and Link post types for non-administrators.
Expand full source codeCollapse full source code
This example removes the Comments, Author and Comments Status meta boxes from the Page edit screen,
Expand full source codeCollapse full source code
If you want to remove a custom taxonomy box from a custom post type edit screen, you can use this:
Expand full source codeCollapse full source code
Even the Publish box can be removed if desired:
In order to remove a widget from the Network Dashboard, you must use wp_network_dashboard_setup hook.
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:
Expand full source codeCollapse full source code