Archive
Old post. Originally published 20 June 2011 on the WordPress version of this site.
Preserved here for the search engines and the curious. Old me had opinions.
Add custom links to WordPress Admin bar
WordPress 3.1 added the handy admin bar. It kinda hovers there giving you some quick and easy links for updating and editing your site. Unfortunately WordPress doesn’t include any kind of admin-side management of this bar. I’ve seen a load of themes that have been customising and adding links to this but wanted to add some of my own. A quick google search found this great article.
The Basic gist of it is below, but the article explains in much greater detail. This needs to go inside your theme’s functions.php file by the way.
function nlk_admin_bar_render() {
global $wp_admin_bar;
// we can remove a menu item, like the COMMENTS link, just by knowing the right $id
$wp_admin_bar->remove_menu('comments');
// we can add a submenu item too
$wp_admin_bar->add_menu( array(
'parent' => 'new-content',
'id' => 'new_media',
'title' => __('Media'),
'href' => admin_url( 'media-new.php')
) );
}
// and we hook our function via
add_action( 'wp_before_admin_bar_render', 'nlk_admin_bar_render' ); Filed under Developer. No comments, on purpose.