Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

enter image description hereI've just installed the Yoast SEO plugin and noticed that a new flyout menu was added to the admin bar once the plugin was activated.

Anyone know is there is a tutorial or example on how this is done?

share|improve this question
    
A couple of related questions that may be of interest, here and here. –  t31os Dec 14 '11 at 1:10
add comment

1 Answer 1

up vote 15 down vote accepted

The action hook admin_bar_menu does the job. Here's what the comment in the core file says:

It includes the action "admin_bar_menu" which should be used to hook in and add new menus to the admin bar. That way you can be sure that you are adding at most optimal point, right before the admin bar is rendered. This also gives you access to the $post global, among others.

Usage:

add_action('admin_bar_menu', 'add_items');

function add_items($admin_bar)
{
//echo "<pre>";
//print_r($admin_bar);
//echo "<pre>";

$admin_bar->add_menu( array(
    'id'    => 'my-item',
            'parent' => 'top-secondary',
    'title' => 'My Item',
    'href'  => '#',
    'meta'  => array(
        'title' => __('My Item'),
    ),
) );
}

You're gonna have to tweak a bit with it, because this code added the new item to the extreme left! I think examining the $admin_bar variable should give you an idea how to add an item.

Update: 'parent' => 'top-secondary' adds the item on the left of 'Howdy...'! So I bet there are other such position values. I'm looking for them ;)

Update 2: 'parent' => 'new-content' adds the item in the New > Post, Media etc menu.

Update 3: 'parent' => 'wp-logo-external' adds the item in the menu popped out from the WordPress logo on the extreme left.

UPDATE:

I have written a blog post with all possible positions for the new item in the admin bar menu... If anyone interested please read here.

share|improve this answer
1  
+1 Thanks. Adding 100,100 at the end of the action moves it to the right of the core menus. –  Scott B Dec 13 '11 at 21:50
    
Awesome, thanks for the 100, 100 thing! I was wondering how to do that. Btw, I'm looking for more such position values, look for the updates in my answer ;) –  Rutwick Gangurde Dec 13 '11 at 21:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.