Remove all meta boxes from WordPress post edit form

This post is more than 11 years old.

When you create a custom post type in WordPress, you can ask register_post_type to generate a default UI for managing your post type in the admin. When you edit your post type, WordPress generates the familiar post editor, just for your post type. You can change it through a variety of hooks, e.g. if you want to add some new meta boxes. But what if you don’t want any meta boxes, not even the standard ones?

I just faced this challenge with a custom post type, where the requirement was to present an edit page that looked more like a settings edit page. No meta boxes (and certainly no meta boxes added promiscuously by other plugins!) Just a simple edit form with Save and Cancel buttons.

The solution I came up with was to wait until all meta boxes have been added by WordPress and the various plugins, then just wipe the list clean and output my own edit fields. When WordPress tries to render the meta boxes on the edit page, there are none to be found. To do this, I used the action hook ‘edit_form_after_title’, which is called after the edit form title is rendered but before the first meta box is rendered. Simple, really.

add_action('edit_form_after_title', 'my_custom_post_edit_form', 100);

/**
* remove all meta boxes, and display the form
*/
function my_custom_post_edit_form($post) {
    global $wp_meta_boxes;

    // remove all meta boxes
    $wp_meta_boxes = array('my_custom_post_type' => array(
        'advanced' => array(),
        'side' => array(),
        'normal' => array(),
    ));

    // show my admin form
    require dirname(__FILE__) . '/views/my-custom-post-edit-form.php';
}

And job is done with simplicity, and without those other plugins’ promiscuous meta boxes!