Removing meta boxes from WordPress dashboard using remove_meta_box

The remove_meta_box function in WordPress is used to remove meta boxes from the WordPress editor. Meta boxes are sections in the WordPress editor that display additional information related to the post or page that is being edited. These sections can include custom fields, categories, tags, and more.

The remove_meta_box function can be used to customize the WordPress editor interface by removing unnecessary or unwanted meta boxes. This can help to streamline the editor interface and make it more user-friendly by removing clutter and focusing on the most important and relevant information.

It’s important to note that the remove_meta_box function only removes the display of the meta box in the WordPress editor. It does not delete any data associated with the meta box. The data is still stored in the WordPress database and can be accessed programmatically if needed.

Parameters Accepted by the remove_meta_box Function

The remove_meta_box function in WordPress accepts three parameters. These parameters are as follows:

  • $id (string): This is a mandatory parameter. It represents the ID of the meta box, which is used in the ‘id’ attribute for the meta box.
  • $screen (string|array|WP_Screen): This is also a required parameter. It identifies the screen or screens where the meta box is displayed. This could be a post type, ‘link’, or ‘comment’. It can accept a single screen ID, a WP_Screen object, or an array of screen IDs.
  • $context (string): This required parameter determines the context within the screen where the box is displayed.

Return Value of the remove_meta_box Function

The remove_meta_box function does not return any value.

Examples

How to Remove the Custom Fields Meta Box from the Post Edit Screen

In this example, we will remove the ‘Custom Fields’ meta box from the post edit screen.

function remove_custom_fields() {
 remove_meta_box('postcustom', 'post', 'normal');
}
add_action('admin_menu', 'remove_custom_fields');

In the above code, remove_meta_box function is used to remove the ‘Custom Fields’ meta box from the post edit screen. The add_action function is used to hook our custom function remove_custom_fields into the admin_menu action hook, which is triggered when the admin menu is being generated.

How to Remove the Slug Meta Box from the Page Edit Screen

In this example, we will remove the ‘Slug’ meta box from the page edit screen.

function remove_slug_box() {
 remove_meta_box('slugdiv', 'page', 'normal');
}
add_action('admin_menu', 'remove_slug_box');

In the above code, remove_meta_box function is used to remove the ‘Slug’ meta box from the page edit screen. The add_action function is used to hook our custom function remove_slug_box into the admin_menu action hook.

How to Remove the Author Meta Box from the Post Edit Screen

In this example, we will remove the ‘Author’ meta box from the post edit screen.

function remove_author_box() {
 remove_meta_box('authordiv', 'post', 'normal');
}
add_action('admin_menu', 'remove_author_box');

In the above code, remove_meta_box function is used to remove the ‘Author’ meta box from the post edit screen. The add_action function is used to hook our custom function remove_author_box into the admin_menu action hook.

Conclusion

The remove_meta_box function in WordPress offers a way to remove existing meta boxes from the WordPress admin interface. This function can be particularly useful when you need to simplify the interface for users by removing unnecessary or confusing meta boxes, or when you want to ensure that certain meta boxes are not accessible for security or other reasons. It is important to note that this function only removes meta boxes from the display; it does not delete any data associated with the meta box.

Related WordPress Functions