How can I extend the functions of the WordPress 3.1 admin bar in my plugins?
I am looking for specific hooks and filters to use in adding links or other features to the admin bar.
A good example of what has already been done is the Yoast WordPress SEO (WordPress Plugin).

Currently there is no documentation available on extending the admin bar. According to The Codex there are two filters to turn it off or not show it:
no_admin_bar()
& show_admin_bar()
Yoast’s plug-in is actually a very good example if all you want to do is add menus. Basically, the admin bar is just an alternate set of links to the same plug-in admin pages you have in the sidebar. To add the top-level SEO menu, Yoast does the following:
$wp_admin_bar->add_menu( array( 'id' => 'wpseo-menu', 'title' => __( 'SEO' ), 'href' => get_admin_url('admin.php?page=wpseo_dashboard'), ) );
This adds a menu named “wpseo-menu” to the admin bar and directs users to the plug-in’s dashboard when they click the link. Child links are added in a similar fashion:
$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __( 'Keyword Research' ), '#', ) );
You just specify the “parent” of the menu you’re adding.
Then you can go as deep as you need to, calling $wp_admin_bar->add_menu()
when you need to and specifying the appropriate information.
For reference, the variable, $wp_admin_bar
is an instance of the class WP_Admin_Bar()
within WordPress. It has several different methods and properties, but the one you’re most interested in here is, obviously, add_menu()
. This method accepts certain parameters:
- title – default false
- href – default false,
- parent – default false – pass the ID value for a submenu of that menu
- id – defaults to a sanitized title value.
- meta – default false – array of any of the following options:
array( 'html' => '', 'class' => '', 'onclick' => '', target => '' );
But the rest of the WP_Admin_Bar()
class is pluggable. It just depends on what exactly you’re trying to do and how you want to do it.
See Also:
- SVN of Yoast’s plug-in: read halfway through the file to find the menu definitions in
wpseo_admin_bar()
- PHPXref of class
WP_Admin_Bar()