The remove_meta_box() WordPress PHP function removes a meta box from one or more screens.
Usage
remove_meta_box( $id, $screen, $context );
Parameters
- $id (string) – Meta box ID (used in the ‘id’ attribute for the meta box)
- $screen (string|array|WP_Screen) – 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) – 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.
More information
See WordPress Developer Resources: remove_meta_box()
Examples
Remove Custom Fields meta box from the Post edit screen
add_action( 'admin_menu', 'wpdocs_remove_post_custom_fields' ); // Remove Custom Fields meta box function wpdocs_remove_post_custom_fields() { remove_meta_box( 'postcustom', 'post', 'normal' ); }
Remove all dashboard widgets
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 }
Remove meta boxes created by plugins
For instances when you want to limit meta boxes by user capability, use the do_meta_boxes
action instead of admin_menu
.
add_action( 'do_meta_boxes', 'wpdocs_remove_plugin_meta_boxes' ); // Remove plugin meta boxes function wpdocs_remove_plugin_meta_boxes() { remove_meta_box( 'example_plugin_meta_box_id', 'post', 'normal' ); }
Remove meta box from multiple screens
add_action( 'admin_menu', 'wpdocs_remove_multiple_screens_meta_box' ); // Remove meta box from multiple screens function wpdocs_remove_multiple_screens_meta_box() { $screens = array( 'post', 'page', 'custom_post_type' ); foreach ( $screens as $screen ) { remove_meta_box( 'example_meta_box_id', $screen, 'normal' ); } }
Remove meta box based on user role
add_action( 'do_meta_boxes', 'wpdocs_remove_meta_box_based_on_role' ); // Remove meta box based on user role function wpdocs_remove_meta_box_based_on_role() { if ( ! current_user_can( 'manage_options' ) ) { remove_meta_box( 'example_meta