Skip to content

Instantly share code, notes, and snippets.

@palimadra
Created March 25, 2012 21:36
Show Gist options
  • Save palimadra/2199997 to your computer and use it in GitHub Desktop.
Save palimadra/2199997 to your computer and use it in GitHub Desktop.
WP - Add links to the WordPress 3.3 toolbar
# Description: [Add Links to WordPress 3.3 New Toolbar]
# Author: Pali Madra
# URL: http://www.agilewebsitedev.com
# Created on: [2012-03-26]
# Revised on: [2012-03-26]
# Instructions: Just put this snippet in the functions.php file of you theme. And note that the second and third of
# $admin_bar->add_menu are add sub menu to the first, and the parent parameter is set to the id of the first
# $admin_bar->add_menu, which in this case is my-item.
# In case you want to delete an item from the toolbar use $admin_bar->remove_menu( 'slug' );
<?php
add_action('admin_bar_menu', 'add_toolbar_items', 100);
function add_toolbar_items($admin_bar){
$admin_bar->add_menu( array(
'id' => 'my-item',
'title' => 'My Item',
'href' => '#',
'meta' => array(
'title' => __('My Item'),
),
));
$admin_bar->add_menu( array(
'id' => 'my-sub-item',
'parent' => 'my-item',
'title' => 'My Sub Menu Item',
'href' => '#',
'meta' => array(
'title' => __('My Sub Menu Item'),
'target' => '_blank',
'class' => 'my_menu_item_class'
),
));
$admin_bar->add_menu( array(
'id' => 'my-second-sub-item',
'parent' => 'my-item',
'title' => 'My Second Sub Menu Item',
'href' => '#',
'meta' => array(
'title' => __('My Second Sub Menu Item'),
'target' => '_blank',
'class' => 'my_menu_item_class'
),
));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment