Skip to content

Instantly share code, notes, and snippets.

@rohmann
Last active December 21, 2015 04:58
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 rohmann/6253298 to your computer and use it in GitHub Desktop.
Save rohmann/6253298 to your computer and use it in GitHub Desktop.
This will give you a "theme location" for nav menus that will be placed in the toolbar. Had this in a repo, but moving to a gist.
<?php
/*
Plugin Name: Custom Toolbar
Plugin URI:
Description:
Author: Alexander Rohmann
Version: 1.0
Author URI: http://github.com/rohmann
*/
register_nav_menu( 'custom-toolbar', 'Custom Toolbar' );
function custom_toolbar_menu($wp_admin_bar){
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ 'custom-toolbar' ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ 'custom-toolbar' ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$url = $menu_item->url;
$parent = $menu_item->menu_item_parent;
$itemid = $menu_item->ID;
$order = $menu_item->menu_order;
if($parent==0)
{
$wp_admin_bar->add_node(array('id' => $itemid, 'title' => $title, 'href' => $url ));
}
else
{
//To-do: Add support for submenu items.
}
}
}
}
add_action('admin_bar_menu','custom_toolbar_menu',999);
@rohmann
Copy link
Author

rohmann commented Sep 10, 2013

This can be used as a standalone plugin, or the code can be placed in at theme's functions.php, or within another plugin.

For quick implementation without coding, use these steps:

  1. Download the PHP file by click clicking the raw icon above (see image) and chosing "Save link as"
  2. Upload that file to the wp-content/mu-plugins folder
    alt text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment