Add custom menu item using wp_nav_menu_items filter

I’ve created these two functions you may use to add custom items to a given menu item present in your menu (page, post, link…). In your case, you can add these function to your functions.php and call them like this: $menu_name=”Your Menu Name”; $name_of_menu_item_to_append_to = ‘My Account’; $id_of_menu_item_to_append_to = get_wp_object_id( $name_of_menu_item_to_append_to, ‘nav_menu_item’ ); $new_submenu_item = … Read more

Add an admin page, but don’t show it on the admin menu

Use a submenu page as parent slug. The admin menu has just two levels, so the imaginary third level will be hidden. Sample code, tested: add_action( ‘admin_menu’, ‘wpse_73622_register_hidden_page’ ); function wpse_73622_register_hidden_page() { add_submenu_page( ‘options-writing.php’, ‘Hidden!’, ‘Hidden!’, ‘exists’, ‘wpse_73622’, ‘wpse_73622_render_hidden_page’ ); # /wp-admin/admin.php?page=wpse_73622 } function wpse_73622_render_hidden_page() { echo ‘<p>hello world</p>’; }

WordPress API Menu/Submenu Order

Here’s an example; First to figure out the order of the sub menu items based upon its array key you can do a var_dump on the $submenu global variable which will output the following; (I’m using the Posts menu and sub menu as an example) //shortened for brevity…. [“edit.php”]=> array(6) { [5]=> array(3) { [0]=> … Read more

How to add sub-menu to a menu generated by wp_nav_menu by using plugin

You can modify your menu by using walker. include(‘subMenu.php’); $menu = wp_nav_menu( array(‘menu’ => ‘YOUR-MENU-NAME’,’menu_class’ => ‘megamenu’,’walker’ => new subMenu)); create a file subMenu.php in theme folder add below code. <?php class subMenu extends Walker_Nav_Menu { function end_el(&$output, $item, $depth=0, $args=array()) { if( ‘Item 3’ == $item->title ){ $output .= ‘<ul class=”sub-menu”> <li class=”menu-item” id=”menu-item-48″><a … Read more

Is It Possible To Add Custom Post Type Menu As Another Custom Post Type Sub Menu

Yes. When you register your post type you need to set show_in_menu to the page you would like it displayed on. Adding a custom post type as a sub-menu of Posts Here we set the “movies” post type to be included in the sub-menu under Posts. register_post_type( ‘movies’, array( ‘labels’ => array( ‘name’ => __( … Read more

Display a portion/ branch of the menu tree using wp_nav_menu()

This was still on my mind so I revisited it and put together this solution, that does not rely on context that much: add_filter( ‘wp_nav_menu_objects’, ‘submenu_limit’, 10, 2 ); function submenu_limit( $items, $args ) { if ( empty( $args->submenu ) ) { return $items; } $ids = wp_filter_object_list( $items, array( ‘title’ => $args->submenu ), ‘and’, … Read more