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.
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; } }
To remove all the widgets from the dashboard screen, use:
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.
Here is an example that removes the Custom Fields box from the Post edit screen.
To remove meta boxes created by plugins,
admin_menuis fired too early, usedo_meta_boxesinstead. This is helpful for instances when you want to limit meta boxes by user capability:This will only remove the excerpt if you are not using Gutenberg editor.
If you are using the Gutenberg editor, use:
Gutenberg editor does not recognize the old way of removing panels. If you like me have custom taxonomies you should remove them with JavaScript.
Then your script…
Other panels can be removed also.
It’s easier not to show meta boxes for custom taxonomies in the editor by adding:
This is added within register_taxonomy().
For example:
Doesn’t work with the new block editor
Here is another example that removes the Excerpt meta box from the Page edit screen,
If you want to remove a custom taxonomy box from a custom post type edit screen, you can use this:
I have several client sites using the LearnDash LMS plugin. For some unknown-to-me reason LearnDash includes a LearnDash Course Grid Settings metabox on EVERY post, page, and custom post type Add or Edit screen.
In an effort to make my clients’ lives easier and less confusing I wanted to remove that metabox from all post types, including pages. To make matters a bit more complicated, sometimes that metabox appears in the “normal-sortables” div, and sometimes in the “advanced-sortables” div.
Here’s a simple function that removes that metabox no matter where it appears, without creating an array of all the post types. Modify as needed for your application.
“`php
/**
* Removes the LearnDash Course Grid Settings metabox
* that appears on all post types.
*/
add_action( ‘do_meta_boxes’, function () {
$post_type = get_post_type() ;
remove_meta_box( ‘learndash-course-grid-meta-box’, $post_type, ‘advanced’ );
remove_meta_box( ‘learndash-course-grid-meta-box’, $post_type, ‘normal’ );
} );
“`
This example removes certain meta boxes from the post edit screens of both the Post and Link post types for non-administrators.
This example removes the Comments, Author and Comments Status meta boxes from the Page edit screen,
commentstatusdivit actually disables comments on any new posts created in $screen. If you want to not see it use thehidden_meta_boxeshookEven 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: