The default_hidden_meta_boxes WordPress PHP filter allows you to modify the default list of hidden meta boxes on the admin screen.
Usage
add_filter('default_hidden_meta_boxes', 'your_custom_function', 10, 2); function your_custom_function($hidden, $screen) { // your custom code here return $hidden; }
Parameters
$hidden
(string[]): An array of IDs of meta boxes hidden by default.$screen
(WP_Screen): WP_Screen object of the current screen.
More information
See WordPress Developer Resources: default_hidden_meta_boxes
Examples
Hide a custom meta box by default
To hide a custom meta box with the ID ‘my_custom_meta_box’ by default:
add_filter('default_hidden_meta_boxes', 'hide_my_custom_meta_box', 10, 2); function hide_my_custom_meta_box($hidden, $screen) { $hidden[] = 'my_custom_meta_box'; return $hidden; }
Show a previously hidden meta box
To show a previously hidden meta box with the ID ‘postcustom’:
add_filter('default_hidden_meta_boxes', 'show_postcustom_meta_box', 10, 2); function show_postcustom_meta_box($hidden, $screen) { $key = array_search('postcustom', $hidden); if (false !== $key) { unset($hidden[$key]); } return $hidden; }
Hide all meta boxes by default
To hide all meta boxes by default:
add_filter('default_hidden_meta_boxes', 'hide_all_meta_boxes', 10, 2); function hide_all_meta_boxes($hidden, $screen) { $all_meta_boxes = array('postcustom', 'trackbacksdiv', 'postexcerpt', 'commentstatusdiv', 'slugdiv'); $hidden = array_merge($hidden, $all_meta_boxes); return $hidden; }
Hide meta boxes for a specific post type
To hide the ‘postcustom’ meta box for the ‘my_post_type’ post type:
add_filter('default_hidden_meta_boxes', 'hide_postcustom_for_my_post_type', 10, 2); function hide_postcustom_for_my_post_type($hidden, $screen) { if ('my_post_type' == $screen->post_type) { $hidden[] = 'postcustom'; } return $hidden; }
Hide meta boxes on a specific screen
To hide the ‘postexcerpt’ meta box on the ‘post’ editing screen:
add_filter('default_hidden_meta_boxes', 'hide_postexcerpt_on_post_screen', 10, 2); function hide_postexcerpt_on_post_screen($hidden, $screen) { if ('post' == $screen->id) { $hidden[] = 'postexcerpt'; } return $hidden; }