Skip to content

Take Control of your WordPress Admin Bar

28 March 20119 comments Code, Installation, Wordpress

wordpress-admin-bar

With WordPress 3.1 came a whole slew of new features. Perhaps the most visually obvious one is the admin bar, which will be a familiar site to any users of wordpress.com.

It provides quick access to all the main areas of your site that you use most often, like creating a new post or page, moderating comments or modifying widgets. It’s probably a good start for the places on your own site that you visit the most, but I’m betting there are other pages that you visit frequently that didn’t find their way on to the admin bar.

Learn how to Do More With WordPress

So here’s how to customize the admin bar to add or remove links as needed. All of these modifications will require modifying your functions.php file. If you’re not sure how to do this, see How To Edit your Theme Files.

Add links to the menu bar

If you want to add links to the menu bar, add this snippet to your functions.php file. The code has a few variables which are explained below:

function my_admin_bar_link() {
	global $wp_admin_bar;
	if ( !is_super_admin() || !is_admin_bar_showing() )
		return;
	$wp_admin_bar->add_menu( array(
	'id' => 'diww',
	'parent' => 'my-blogs',
	'title' => __( 'Do It With WordPress'),
	'href' => admin_url( 'http://www.doitwithwordpress.com/spacer.gif' )
	) );
}
add_action('admin_bar_menu', 'my_admin_bar_link');

The variables that you’ll interested in are id, parent, title and href. id is merely a unique identifier for the link and parent dictates which menu the link will appear in. In this example, it is shown under the my-blogs menu. The following list shows you all the different menus that WordPress supports natively, but if you want a different menu altogether, you can add a custom one:

  • my-account-with-avatar or my-account – Your account information (appears as your name)
  • my-blogs – All the sites that you are a member of (appears as My Sites)
  • edit – For editing posts or pages (appears as Edit Post or Edit Page)
  • new-content – For adding new posts or pages (appears as Add New)
  • comments – Comment moderation area (appears as Comments)
  • appearance – Modifying widgets, menus etc. (appears as Appearance)
  • updates – For updating plugins and themes etc. (appears as Updates)
  • get-shortlink – Provides shortlink for current page (appears as Get Shortlink)

The title variable will be what is shown in the menu for the item and the href variable is the URL for the link. So in the example above, I’ve created a link called Do It With WordPress under the My Sites menu which links to the admin area of my WordPress site.

Remove menus altogether

To completely remove a menu from the admin bar, you can use the function below, replacing the menu names with the ones that you want to remove. You can remove more or less than the 2 that I have shown by adding or removing lines:

function remove_admin_bar_links() {
	global $wp_admin_bar;
	$wp_admin_bar->remove_menu('my-blogs');
	$wp_admin_bar->remove_menu('my-account-with-avatar');
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

Create a custom menu

If you’d rather keep all your links under a completely new menu, you can create one by using the following function:

function my_admin_bar_menu() {
	global $wp_admin_bar;
	if ( !is_super_admin() || !is_admin_bar_showing() )
		return;
	$wp_admin_bar->add_menu( array(
	'id' => 'social_networks',
	'title' => __( 'Social Networks'),
	'href' => FALSE ) );
	$wp_admin_bar->add_menu( array(
	'parent' => 'social_networks',
	'title' => __( 'Facebook'),
	'href' => 'http://www.facebook.com/pages/Do-It-With-WordPress/154784051207520' ) );
	$wp_admin_bar->add_menu( array(
	'parent' => 'social_networks',
	'title' => __( 'Twitter'),
	'href' => 'http://www.twitter.com/dowithwordpress' ) );
}
add_action('admin_bar_menu', 'my_admin_bar_menu');

In this example, I created a new menu called Social Networks, with two links under it, one to my Facebook page and one to my Twitter page. Pretty swish huh? You can also set what position it will take in the admin bar, by setting an order value. Just change the last line to the following, where 1000 is the order value:

add_action('admin_bar_menu', 'my_admin_bar_menu', 1000 );

Creative menu ideas

As I got to thinking about it, you could really put some cool things together using this functionality. For example, you could create a menu of URLs that will submit your post to social networking sites like Facebook and Twitter, or you could create a set of links for shortening your URL with different services like is.gd and bit.ly. I also saw a really creative idea of incorporating a form for searching a site in to the admin bar. The possibilities are endless, so what are you going to do with it? I’d love to see what you come up with.

Remove the bar altogether

Perhaps you’ve decided that the WordPress Admin Bar isn’t for you. All you need to do to remove the WordPress Admin Bar is go to your profile (Users > Your Profile from the dashboard) and uncheck the two boxes which determine when the admin bar should be displayed and it’ll never bother you again. That was painless wasn’t it…

Related posts:

  1. Facebook and Twitter Buttons Without Plugins
  2. Create Your Own Fast Social Sharing Buttons For WordPress
  3. WordPress Essentials – Installing Themes
  4. Move Your WordPress Site To A New Domain Seamlessly
  5. How to Edit Your Theme Files [WORDPRESS]

StudioPress Premium WordPress Themes

About the Author

Dave Clements designs awesome websites and offers WordPress consulting services in his spare time, along with eating Wheat Thins, spending time with friends and family, watching Indie films and playing with his array of Apple products.

Like it? Share it!

Tweet this!Share on FacebookStumbleUponDigg This!

Comments

  1. Ovidiu April 29, 2011

    trying to add a link to the comments menu, doesn’t work for me :-( it works if I take the parent part out so it displays as top level menu:

    `function addNetworkComments($wp_admin_bar) {
    if ( is_user_logged_in() ){
    $wp_admin_bar->add_menu( array( ‘id’ => ‘discutiile_mele’, ‘parent’ => ‘comments’, ‘title’ => __( ‘Discutiile mele’),
    ‘href’ => admin_url( http://www.doitwithwordpress.com/spacer.gif )
    ) );
    }}
    add_action(‘admin_bar_menu’, ‘addNetworkComments’, 0);`

    • Dave Clements April 29, 2011

      That’s interesting – I can’t see anything inherently wrong with your code – it should work as far as I’m concerned. So you can install it without a parent by omitting that variable?

      • Ovidiu April 30, 2011

        right, if I take out the id and parent stuff it works. have tried a few variations but can’t get it to work. do I have to add some more declarations to the parent to make the comment part a drop down (as it isn’t by default)? tried changing the parent to appearance as that is a drop down already, but doesn’t work either…

        • Dave Clements April 30, 2011

          No, you don’t have to do anything to make the menu a drop-down, but are you saying that you don’t currently have the comments menu in your admin bar?

          • Ovidiu May 1, 2011

            no.
            I DO have the comments parent menu but I can’t attach this menu item to it. I can make it a root level entry though. and I can’t attach it to any other menu either…

  2. ed May 4, 2011

    How would I customize the look for subscribers….I want to delete dashboard and edit my profile for subscribers and keep logout…maybe add another link or two under their name…Any help would be great!

    • Dave Clements May 5, 2011

      When you say you want to change the look for your subscribers, does that mean that you want a different set of links in the admin bar for different user levels?

  3. Unknown May 5, 2011

    Excellent tutorial, something i was looking for, but can we put link by which user can bookmark content to their social profile.

Add a Comment

Required

Required

Optional

CommentLuv Enabled
Site map WordPress Tutorials by Do It With WordPress News