Skip to content

Instantly share code, notes, and snippets.

@butlerblog
Created September 10, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save butlerblog/07f1e90e4da36b5a891a to your computer and use it in GitHub Desktop.
Save butlerblog/07f1e90e4da36b5a891a to your computer and use it in GitHub Desktop.
How to Attach a navigation menu to the admin bar (from: http://wpsnipp.com/index.php/functions-php/attach-a-navigation-menu-to-the-admin-bar/)
<?php
add_action( 'admin_bar_menu', 'wpse15186_admin_bar_menu' );
function wpse15186_admin_bar_menu( &$wp_admin_bar )
{
$menu = wp_get_nav_menu_object( 'WPSE 15186 test menu' );
$menu_items = wp_get_nav_menu_items( $menu->term_id );
$wp_admin_bar->add_menu( array(
'id' => 'wpse15186-menu-0',
'title' => 'WPSE 15186 menu',
) );
foreach ( $menu_items as $menu_item ) {
$wp_admin_bar->add_menu( array(
'id' => 'wpse15186-menu-' . $menu_item->ID,
'parent' => 'wpse15186-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 ),
),
) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment