WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/remove meta box

Description

The remove_meta_box() function was introduced in WordPress 2.6. It allows plugin developers to remove sections from the Write Post, Write Page, and Write Link editing pages.

Usage

 <?php remove_meta_box$id$page$context ); ?> 

Parameters

$id 
(string) HTML 'id' attribute of the meta box to remove. Some of the available metabox 'id' attributes are given below.
  • 'commentstatusdiv' - Comments status metabox.
  • 'commentsdiv' - Comments metabox.
  • 'slugdiv' - Slug metabox.
  • 'revisionsdiv' - Revisions metabox.
  • 'authordiv' - Author metabox.
  • 'postcustom' - Custom fields metabox.
  • 'postexcerpt' - Excerpt metabox.
  • 'trackbacksdiv' - Trackbacks metabox.
  • 'postimagediv' - Featured image metabox.
  • 'formatdiv' - Formats metabox.
  • 'tagsdiv-post_tag' - Tags metabox.
  • 'categorydiv' - Categories metabox.
$page 
(string) The type of Write screen to remove the meta box from ('post', 'page', or 'link' or any registered custom post type like 'product')
$context 
(string) Normal, advanced, or side

Example

This example removes certain meta boxes from both the link and post type pages for non-administrators.

if (is_admin()) :
function my_remove_meta_boxes() {
 if(!current_user_can('administrator')) {
  remove_meta_box('linktargetdiv', 'link', 'normal');
  remove_meta_box('linkxfndiv', 'link', 'normal');
  remove_meta_box('linkadvanceddiv', 'link', 'normal');
  remove_meta_box('postexcerpt', 'post', 'normal');
  remove_meta_box('trackbacksdiv', 'post', 'normal');
  remove_meta_box('commentstatusdiv', 'post', 'normal');
  remove_meta_box('postcustom', 'post', 'normal');
  remove_meta_box('commentstatusdiv', 'post', 'normal');
  remove_meta_box('commentsdiv', 'post', 'normal');
  remove_meta_box('revisionsdiv', 'post', 'normal');
  remove_meta_box('authordiv', 'post', 'normal');
  remove_meta_box('sqpt-meta-tags', 'post', 'normal');
 }
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );
endif;

Here is an example that removes the custom field box from the post screen.

<?php 
function remove_post_custom_fields() {
	remove_meta_box( 'postcustom' , 'post' , 'normal' ); 
}
add_action( 'admin_menu' , 'remove_post_custom_fields' );
?>

Here is another example that removes the excerpt meta box from the page editing screen,

<?php 
function remove_page_excerpt_field() {
	remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); 
}
add_action( 'admin_menu' , 'remove_page_excerpt_field' );
?>

This example removes the comments,author and comments status meta boxes from the page editing screen,

<?php 
function remove_page_fields() {
 remove_meta_box( 'commentstatusdiv' , 'page' , 'normal' ); //removes comments status
 remove_meta_box( 'commentsdiv' , 'page' , 'normal' ); //removes comments
 remove_meta_box( 'authordiv' , 'page' , 'normal' ); //removes author 
}
add_action( 'admin_menu' , 'remove_page_fields' );
?>

If you want to remove a custom taxonomy box within a custom post type, you can use

function remove_custom_taxonomy()
{
	remove_meta_box( 'tagsdiv-custom_taxonomy_slug', 'custom_post_slug', 'side' );
}
add_action( 'admin_menu', 'remove_custom_taxonomy' );

Even the "Publish" box can be removed if desired

function remove_publish_box()
{
	remove_meta_box( 'submitdiv', 'custom_post_slug', 'side' );
}
add_action( 'admin_menu', 'remove_publish_box' );

Further Reading

Source File

remove_meta_box() is located in wp-admin/includes/template.php

See also index of Function Reference and index of Template Tags.
This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.
This page is marked as incomplete. You can help Codex by expanding it.