The meta_box_prefs() WordPress PHP function prints the meta box preferences for screen meta.
Usage
meta_box_prefs( $screen );
Example:
$screen = get_current_screen(); meta_box_prefs( $screen );
Parameters
- $screen (WP_Screen) – The screen object for which the meta box preferences should be printed.
More information
See WordPress Developer Resources: meta_box_prefs
This function was introduced in WordPress version 2.7.
Examples
Display meta box preferences on a custom admin page
Create a custom admin page and display the meta box preferences on that page.
add_action( 'admin_menu', 'my_custom_admin_page' );
function my_custom_admin_page() {
$hook = add_menu_page( 'My Custom Page', 'My Custom Page', 'manage_options', 'my-custom-page', 'my_custom_page_callback' );
add_action( "load-$hook", 'my_custom_page_screen_options' );
}
function my_custom_page_callback() {
$screen = get_current_screen();
meta_box_prefs( $screen );
}
function my_custom_page_screen_options() {
$screen = get_current_screen();
if ( 'toplevel_page_my-custom-page' !== $screen->id ) {
return;
}
add_meta_box( 'my_custom_meta_box', 'My Custom Meta Box', 'my_custom_meta_box_callback', $screen );
}
function my_custom_meta_box_callback() {
echo 'This is my custom meta box content.';
}
Add meta box preferences to a custom post type
Add meta box preferences to a custom post type admin screen.
add_action( 'init', 'my_custom_post_type' );
function my_custom_post_type() {
register_post_type( 'my_custom_post', array(
'labels' => array( 'name' => 'My Custom Post' ),
'public' => true,
) );
}
add_action( 'add_meta_boxes', 'my_custom_post_meta_boxes' );
function my_custom_post_meta_boxes() {
add_meta_box( 'my_custom_meta_box', 'My Custom Meta Box', 'my_custom_meta_box_callback', 'my_custom_post' );
}
function my_custom_meta_box_callback() {
echo 'This is my custom meta box content.';
}
add_action( 'admin_footer', 'my_custom_post_meta_box_prefs' );
function my_custom_post_meta_box_prefs() {
$screen = get_current_screen();
if ( 'my_custom_post' !== $screen->post_type ) {
return;
}
meta_box_prefs( $screen );
}
Display meta box preferences on user profile page
Add meta box preferences to the user profile page.
add_action( 'show_user_profile', 'my_user_profile_meta_box_prefs' );
add_action( 'edit_user_profile', 'my_user_profile_meta_box_prefs' );
function my_user_profile_meta_box_prefs( $user ) {
$screen = get_current_screen();
meta_box_prefs( $screen );
}
Add meta box preferences to a custom taxonomy edit screen
Add meta box preferences to a custom taxonomy edit screen.
add_action( 'init', 'my_custom_taxonomy' );
function my_custom_taxonomy() {
register_taxonomy( 'my_custom_tax', 'post', array( 'labels' => array( 'name' => 'My Custom Taxonomy' ) ) );
}
add_action( 'my_custom_tax_edit_form_fields', 'my_custom_tax_meta_box_prefs