Metabox Tutorial – remove_meta_box() Function

Share this Article

WordPress remove_meta_box() function name itself telling to remove a metabox from wordpress. To remove any metabox we need to pass some parameters while using this function.

We can remove metabox from wordpress dashboard, posts, pages, categories, etc. Removes a meta box from one or more screens.

Syntax

remove_meta_box( string $id, string|array|WP_Screen $screen, string $context )

Parameters details

$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.

We can find this function inside File: wp-admin/includes/template.php

Example

add_action( 'admin_menu' , 'owt_remove_page_fields' );
 
/**
 * Remove meta boxes from page screen
 */
function owt_remove_page_fields() {
    remove_meta_box( 'formatdiv' , 'post' , 'normal' ); //removes post format
    remove_meta_box( 'commentstatusdiv' , 'post' , 'normal' ); //removes comments status
    remove_meta_box( 'authordiv' , 'post' , 'normal' ); //removes author 
}

Above code will remove Format, Author, Discussion metaboxes from wordpress create post / edit post page. You can add this code into your custom plugin code or add inside activated theme functions.php file.

formatdiv, commentstatusdiv, authordiv are metabox IDs for Format, Author, Discussion metaboxes.

Was this post helpful?

PHP Web Development Courses on Offer in just $4
PHP Web Development Courses on Offer in just $4