How to add a navigation menu to WordPress admin bar
If you want to add a new menu in the admin bar then the following code is useful. Just add the below code to your functions.php file in theme folder. The below will create “MAX menu” , you can rename it to ABC, MY MENU or whatever you like.
<?php add_action( 'admin_bar_menu', 'max_admin_bar_menu' ); function max_admin_bar_menu( &$wp_admin_bar ) { $menu = wp_get_nav_menu_object( 'MAX menu' ); $menu_items = wp_get_nav_menu_items( $menu->term_id ); $wp_admin_bar->add_menu( array( 'id' => 'max-menu-0', 'title' => 'MAX menu', ) ); foreach ( $menu_items as $menu_item ) { $wp_admin_bar->add_menu( array( 'id' => 'max-menu-' . $menu_item->ID, 'parent' => 'max-menu-' . $menu_item->menu_item_parent, 'title' =>$menu_item->title, 'href' =>$menu_item->url, 'meta' => array( 'title' =>$menu_item->attr_title, 'target' =>$menu_item->target, 'class' => implode( ' ', $menu_item->classes ), ), ) ); } } ?> |