Using WordPress ‘hidden_meta_boxes’ PHP filter

The hidden_meta_boxes WordPress PHP Filter allows you to modify the list of hidden meta boxes for a specific screen.

Usage

add_filter('hidden_meta_boxes', 'your_custom_function', 10, 3);

function your_custom_function($hidden, $screen, $use_defaults) {
    // your custom code here
    return $hidden;
}

Parameters

  • $hidden (string[]): An array of IDs of hidden meta boxes.
  • $screen (WP_Screen): WP_Screen object of the current screen.
  • $use_defaults (bool): Whether to show the default meta boxes. Default is true.

More information

See WordPress Developer Resources: hidden_meta_boxes

Examples

Hide a specific meta box

Hide the ‘postexcerpt’ meta box on the post edit screen.

add_filter('hidden_meta_boxes', 'hide_post_excerpt', 10, 3);

function hide_post_excerpt($hidden, $screen, $use_defaults) {
    if ($screen->id == 'post') {
        $hidden[] = 'postexcerpt';
    }
    return $hidden;
}

Show all meta boxes

Force all meta boxes to be visible on the page edit screen.

add_filter('hidden_meta_boxes', 'show_all_meta_boxes', 10, 3);

function show_all_meta_boxes($hidden, $screen, $use_defaults) {
    if ($screen->id == 'page') {
        $hidden = array();
    }
    return $hidden;
}

Hide specific meta boxes for custom post type

Hide ‘trackbacksdiv’ and ‘commentstatusdiv’ meta boxes for the custom post type ‘event’.

add_filter('hidden_meta_boxes', 'hide_event_meta_boxes', 10, 3);

function hide_event_meta_boxes($hidden, $screen, $use_defaults) {
    if ($screen->id == 'event') {
        $hidden[] = 'trackbacksdiv';
        $hidden[] = 'commentstatusdiv';
    }
    return $hidden;
}

Hide all default meta boxes

Hide all default meta boxes on the post edit screen.

add_filter('hidden_meta_boxes', 'hide_all_default_meta_boxes', 10, 3);

function hide_all_default_meta_boxes($hidden, $screen, $use_defaults) {
    if ($screen->id == 'post' && $use_defaults) {
        $hidden = array_merge($hidden, array_keys(get_registered_meta_boxes('post')));
    }
    return $hidden;
}

Show a specific meta box

Force the ‘postimagediv’ meta box to be visible on the post edit screen.

add_filter('hidden_meta_boxes', 'show_post_image', 10, 3);

function show_post_image($hidden, $screen, $use_defaults) {
    if ($screen->id == 'post') {
        $index = array_search('postimagediv', $hidden);
        if (false !== $index) {
            unset($hidden[$index]);
        }
    }
    return $hidden;
}