nav_menu_meta_box_object
Allows you to change the object used to build a meta box in the menu item selection accordion on the admin menu creation page.
The object can be an instance of:
- WP_Post_Type for the Posts, Pages, and custom post type meta boxes.
- WP_Taxonomy for the Categories, Tags, Format, and custom taxonomy meta boxes.
Returning a falsey value such as false or null instead of an object prevents the current meta box from being added to the accordion.
Example object for the Posts meta box:
WP_Post_Type Object( [name] => post [label] => Posts [labels] => stdClass Object( [name] => Posts [singular_name] => Post [add_new] => Add New [add_new_item] => Add New Post [edit_item] => Edit Post [new_item] => New Post [view_item] => View Post [view_items] => View Posts [search_items] => Search Posts [not_found] => No posts found. [not_found_in_trash] => No posts found in Trash. [parent_item_colon] => [all_items] => All Posts [archives] => Post Archives [attributes] => Post Attributes [insert_into_item] => Insert into post [uploaded_to_this_item] => Uploaded to this post [featured_image] => Featured image [set_featured_image] => Set featured image [remove_featured_image] => Remove featured image [use_featured_image] => Use as featured image [filter_items_list] => Filter posts list [items_list_navigation] => Posts list navigation [items_list] => Posts list [menu_name] => Posts [name_admin_bar] => Post ) [description] => [public] => 1 [hierarchical] => [exclude_from_search] => [publicly_queryable] => 1 [show_ui] => 1 [show_in_menu] => 1 [show_in_nav_menus] => 1 [show_in_admin_bar] => 1 [menu_position] => 5 [menu_icon] => [capability_type] => post [map_meta_cap] => 1 [register_meta_box_cb] => [taxonomies] => Array() [has_archive] => [query_var] => [can_export] => 1 [delete_with_user] => 1 [_builtin] => 1 [_edit_link] => post.php?post=%d [cap] => stdClass Object( [edit_post] => edit_post [read_post] => read_post [delete_post] => delete_post [edit_posts] => edit_posts [edit_others_posts] => edit_others_posts [publish_posts] => publish_posts [read_private_posts] => read_private_posts [read] => read [delete_posts] => delete_posts [delete_private_posts] => delete_private_posts [delete_published_posts] => delete_published_posts [delete_others_posts] => delete_others_posts [edit_private_posts] => edit_private_posts [edit_published_posts] => edit_published_posts [create_posts] => edit_posts ) [rewrite] => [show_in_rest] => 1 [rest_base] => posts [rest_controller_class] => WP_REST_Posts_Controller [_default_query] => Array( [post_status] => publish ) )
Usage
add_filter( 'nav_menu_meta_box_object', 'wp_kama_nav_menu_meta_box_object_filter' );
/**
* Function for `nav_menu_meta_box_object` filter-hook.
*
* @param WP_Post_Type|false $post_type The current object to add a menu items meta box for.
*
* @return WP_Post_Type|false
*/
function wp_kama_nav_menu_meta_box_object_filter( $post_type ){
// filter...
return $post_type;
}
- $meta_box_object(object)
- Current object used to build the accordion meta box.
Examples
#1 Change the Categories meta box title
add_filter( 'nav_menu_meta_box_object', function ( $obj ) {
if ( 'category' == $obj->name ) {
$obj->labels->name = 'My Categories';
}
return $obj;
} );
#2 Remove the Format meta box
add_filter( 'nav_menu_meta_box_object', function ( $obj ) {
if ( 'post_format' == $obj->name ) {
$obj = null;
}
return $obj;
} );Changelog
| Since 3.0.0 | Introduced. |
Where the hook is called
nav_menu_meta_box_object
nav_menu_meta_box_object
nav_menu_meta_box_object
wp-admin/includes/nav-menu.php 277
$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
wp-admin/includes/ajax-actions.php 1920
$item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object );
wp-admin/includes/nav-menu.php 310
$tax = apply_filters( 'nav_menu_meta_box_object', $tax );
Where the hook is used in WordPress
wp-admin/includes/admin-filters.php 52
add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' );