The customize_nav_menu_available_item_types WordPress filter allows you to modify the available navigation menu item types.
Usage
add_filter('customize_nav_menu_available_item_types', 'your_custom_function'); function your_custom_function($item_types) { // your custom code here return $item_types; }
Parameters
- $item_types (array): An array of available navigation menu item types.
More information
See WordPress Developer Resources: customize_nav_menu_available_item_types
Examples
Add a custom post type to the available menu item types
This example adds a custom post type, ‘portfolio’, to the available menu item types.
add_filter('customize_nav_menu_available_item_types', 'add_portfolio_to_nav_menu'); function add_portfolio_to_nav_menu($item_types) { $item_types[] = array( 'title' => 'Portfolio', 'type' => 'post_type', 'object' => 'portfolio' ); return $item_types; }
Remove the ‘Pages’ menu item type
This example removes the ‘Pages’ menu item type from the available menu item types.
add_filter('customize_nav_menu_available_item_types', 'remove_pages_from_nav_menu'); function remove_pages_from_nav_menu($item_types) { foreach ($item_types as $key => $item_type) { if ($item_type['object'] === 'page') { unset($item_types[$key]); } } return $item_types; }
Add a custom taxonomy to the available menu item types
This example adds a custom taxonomy, ‘product_category’, to the available menu item types.
add_filter('customize_nav_menu_available_item_types', 'add_product_category_to_nav_menu'); function add_product_category_to_nav_menu($item_types) { $item_types[] = array( 'title' => 'Product Categories', 'type' => 'taxonomy', 'object' => 'product_category' ); return $item_types; }
Change the title of the ‘Posts’ menu item type
This example changes the title of the ‘Posts’ menu item type to ‘Articles’.
add_filter('customize_nav_menu_available_item_types', 'change_posts_title_to_articles'); function change_posts_title_to_articles($item_types) { foreach ($item_types as $key => $item_type) { if ($item_type['object'] === 'post') { $item_types[$key]['title'] = 'Articles'; } } return $item_types; }
Remove all default menu item types
This example removes all default menu item types, leaving only custom ones.
add_filter('customize_nav_menu_available_item_types', 'remove_all_default_menu_item_types'); function remove_all_default_menu_item_types($item_types) { return array(); }