Modifying the WordPress Admin Toolbar

No Comments

The Admin Toolbar was introduced back in WordPress 3.1 (trivia points if you know the code name of WordPress 3.1 without looking it up) and people still love it or hate it. On one hand it allows admins and privileged users to quickly access features such as comments or to easily create new posts, pages and more. Detractors feel it clutters the experience and takes up screen real estate much like the hated browser toolbar (not related to WordPress).

If you’re one of the later, you can deactivate the Admin Toolbar and be merrily on your way. If you don’t mind the WordPress Admin Toolbar would like to see how you can harness it to improve your site, read on!

In our example we are going to add new, custom menu items to the Admin Toolbar. Let’s say you are a theme developer or admin and you want to give your users quick access to links, resources or tools. You can make them an integrated part of your theme and they’ll always be use a mouse click away for them and you. In our example below, we want to add a Support menu which will allow users to access a Paid Support site or Community Support (such as a free forum).

By adding the following code to your theme’s functions.php, these items will appear. The values are merely placeholders and you can add multiple menus and menu items as needed.

[code]
add_action(‘admin_bar_menu’, ‘add_toolbar_items’, 100);
function add_toolbar_items($admin_bar){
$admin_bar->add_menu( array(
‘id’ => ‘custom-1’,
‘title’ => ‘Support’,
‘href’ => ‘#’,
‘meta’ => array(
‘title’ => __(‘Support’),
),
));
$admin_bar->add_menu( array(
‘id’ => ‘custom-sub-1’,
‘parent’ => ‘custom-1’,
‘title’ => ‘Paid Support’,
‘href’ => ‘#’,
‘meta’ => array(
‘title’ => __(‘Paid Support’),
‘target’ => ‘_blank’,
‘class’ => ‘custom-sub1-class’
),
));
$admin_bar->add_menu( array(
‘id’ => ‘custom-sub-2’,
‘parent’ => ‘custom-1’,
‘title’ => ‘Community Support’,
‘href’ => ‘#’,
‘meta’ => array(
‘title’ => __(‘Community Support’),
‘target’ => ‘_blank’,
‘class’ => ‘custom-sub2-class’
),
));
}
[/code]

Parameters and Customization:

  • id: Provides a unique id so WordPress can recognize the new menu item
  • title: Human readable name for the menu item
  • href: The URL the menu item should link to.
  • meta: Additional parameters such as class to style your menu item and target which allow you to open the destination in a new browser window.

Trivia Answer: WordPress 3.1’s code name was “Reinhardt”.

* Standard disclaimer here. Before editing any critical files in WordPress you should make a backup and be prepared to roll back any changes in case you run into problems or conflicts. This code is offered with no guarantees or support. Use at your own discretion.

Need help implementing this tip in your WordPress site? Contact us for our professional services.  We can also provide support & expertise in convenient “blocks” to suit your short and long term needs.

I'm the front-man of It's WordPress. I come from a diverse array of backgrounds, enjoying the opportunity to expand my knowledge base and skill set by re-inventing myself. I enjoy environments that focus on emerging information, technology and concepts. I put on the technical hat in my early 20s and never really looked back. I'm love technology and the internet, as well as the outdoors and avidly hike, kayak and camp every chance I get.

About Us

We can take you from concept, through design, development and deployment in one seamless process. Whether you choose a self-managed web site or need a continuing support relationship; we've got you covered.

Request Consulation

Ready to transform your vision into a reality? Just looking to see what it takes to get the ball rolling. Tell us about your project and we can help. No spam. No obligation. Just answers.

More from our blog

See all posts