How to Add Links to WordPress 3.3′s Admin Bar

One of the great additions to WordPress 3.3 is the updated admin bar. Not only does the admin bar add some nifty quick links – but you and plugins can add links of your own to it. It’s pretty simple and straightforward.

How to Add a Single Link to the WordPress Admin Bar

<?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'),			
		),
	));
} ?>

How to Add a Dropdown Menu to the WordPress Admin Bar

<?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'
		),
	));
} ?>

Source: Add Links to WordPress 3.3 New Toolbar

Follow wpLifeGuard

« Back to Blog