How to Add or Remove Links From the WordPress 3.1 Admin Bar

The new WordPress 3.1 admin bar is fairly handy and it can save you quite a bit of time when accessing your most-used menu items. However, not every WordPress installation is the same. We’re going to show you how you can customize the admin bar to suit your particular needs.

How to remove links from the admin bar

Take a look at the default admin bar:

Now, let’s turn something off. Let’s say, for example, that you don’t have comments enabled for your site and therefore do not require easy access to the comments menu item. Here’s how you can remove that from the admin bar. Add this snippet to your theme’s functions.php file:

1
2
3
4
5
6
7
function mytheme_admin_bar_render() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('comments');
    
}

add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );

Inspired by code from wp-snippets.com

Now your admin bar should look something like this:

Pretty simple, right? If you take a look at /wp-includes/admin-bar.php, you can find ID’s for other items you’d like to remove.

How to add links to the admin bar

By default the Add New menu item on the admin bar contains Post and Page. In this example, we’re going to add Media to the drop down, as that seems like it might come in handy. Add this snippet to your theme’s functions.php file:

1
2
3
4
5
6
7
8
9
10
11
12
function mytheme_admin_bar_render() {
    global $wp_admin_bar;
        $wp_admin_bar->add_menu( array(
        'parent' => 'new-content',
        'id' => 'new_media',
        'title' => __('Media'),
        'href' => admin_url( 'media-new.php')
    ) );
    
}

add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );

You can follow this same pattern for any new item that you’d like to add to the admin bar, replacing each ID depending on what you’d like to add to the menu. Here are the basics we’re working with, as listed on wp-snippets.com:

my-account / my-account-with-avatar : the first link, to your account. Note that the ID here changes depending on if you have Avatars enabled or not.
my-blogs : the ‘My Sites’ menu if the user has more than one site
get-shortlink : provides a Shortlink to that page
edit : link to Edit [content-type]
new-content : the ‘Add New’ dropdown
comments : the ‘Comments’ dropdown
appearance : the ‘Appearance’ dropdown
updates : the ‘Updates’ dropdown

I hope these two examples of removing and adding links to the admin bar will help you get started on your own customizations. There will probably be plugins available for this soon, but why use a plugin when you can keep your site lean and do it yourself?

Featured Plugin - WordPress Facebook Plugin

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

Featured Plugin - WordPress Pop-Up Chat Plugin

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - WordPress Newsletter Plugin

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Featured Plugin - WordPress Membership Site Plugin

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - WordPress Wiki Plugin

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - WordPress Google Maps Plugin

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - WordPress Q&A Site Plugin

It's now incredibly easy to start your own Q&A site using nothing more than WordPress - The Q&A plugin simply and brilliantly transforms any site, or page, into a perfect support or Q&A environment.
Find out more

Featured Plugin - WordPress Ecommerce Shopping Cart Plugin

Out of all the WordPress ecommerce plugins available, MarketPress has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - WordPress Infinite SEO Plugin

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

Comments (18)

  1. Thank you for the tip, this is very useful.

    The next step would be to edit the bar for all blogs in a network. Would that only be possible by:

    1- Changing the core files, so you need to redo the changes after every WP update
    2- Change all the themes functions.php files (can be hundreds), and if you want to change a link, you need to do it all again?
    3- Some better way?

    Thanks!

    ps: the tab-order of this theme is seriously messed up! hard to navigate the comment fields :)

  2. @Harry: check out the link Adam posted, that answers your question.

    @Sarah: I’like to know how I can add a simple link to my admin bar and how can I position it? I’d like ot have it added on the right side of the admin bar

  3. This code is good, but if we look deeper in the WP Admin Bar class, we’ll see that the ‘remove_menu’ is now just a wrapper version of ‘remove_node’, which means WP team now use the term ‘node’ instead of ‘menu.

    And while we can copy this code to functions.php file, it’s better to use a plugin like Hide Admin Menu to reduce the effort. This plugin allow us to select which admin bar items need to be hidden based on user role, just select the check boxes and Save.

Participate