Skip to content

Instantly share code, notes, and snippets.

@landbryo
Last active May 24, 2018 16:09
Show Gist options
  • Save landbryo/6c4eb3847f9982dcad9cfdd20d4b179b to your computer and use it in GitHub Desktop.
Save landbryo/6c4eb3847f9982dcad9cfdd20d4b179b to your computer and use it in GitHub Desktop.
Creates menu in WordPress admin bar.
// ADD TOOLBAR MENU ITEMS //
function add_scree_toolbar($admin_bar){
$menuName = 'You Menu Name';
$screeMenu = wp_get_nav_menu_items($menuName);
$admin_bar->add_menu(array(
'id' => 'parent-item',
'title' => 'Menu',
'href' => '#',
'meta' => array(
'title' => __('Menu')
)
));
foreach ($screeMenu as $menuItem) {
$menuArgs = array(
'id' => $menuItem->ID,
'title' => $menuItem->title,
'href' => $menuItem->url,
'parent' => 'ai-item',
'meta' => array(
'title' => __($menuItem->title)
)
);
$admin_bar->add_menu($menuArgs);
}
}
add_action('admin_bar_menu', 'add_scree_toolbar', 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment