8 Ways to Hack and Improve Your WordPress Toolbar - ManageWP

8 Ways to Hack and Improve Your WordPress Toolbar

8 Ways to Hack and Improve Your WordPress Toolbar

Ah, the ubiquitous WordPress toolbar.

Although it attracted the ire of some users upon its release in version 3.3 of WordPress, in my humble opinion, there is no doubting its usefulness.

It bridges the gap between your live blog and the backend. It allows you to quickly access your dashboard, edit posts, check comments, update plugins, and much more. A few moments spent familiarizing yourself with it can help you get things done more quickly.

But that’s just the default toolbar. There are actually a whole bunch of things you can do to improve its functionality, and today, I want to go through my favorites.

1. Add Custom Menu Items

Let’s start with a plugin. By default, Enhanced Admin Bar with Codex Search adds an extra drop down menu to your toolbar:

Enhanced Admin Bar

That’s pretty good for a start. But it also enables you to create your own custom menu items, containing whatever links you like.

This is easily done through WordPress’ custom menu section. Just create your custom menu, then select it in the “Admin Bar Custom Navigation Menu” drop down box:

Enhanced Admin Bar

Your custom menu will then display on the toolbar:

Enhanced Admin Bar

Pretty cool, right? You can download Enhanced Admin Bar with Codex Search from WordPress.org here.

2. Inbuilt Analytics

I am a huge fan of Clicky analytics. I don’t consider it a replacement of Google Analytics, but it is by far my preferred choice for on the fly analysis:

Clicky
That’s some good-looking analytics right there.

Another great reason to use Clicky analytics is the Clicky Analytics by Yoast plugin. Not only does it make implementing Clicky on WordPress blogs a piece of cake, it also allows you to ignore admin users, store names of commenters, track posts and pages as goals, and much more.

You may be wondering what this has to do with the toolbar. Well, it’s just this simple graphic:

Clicky by Yoast

This graphic represents visitors to your site in the last 48 hours. If you click on it, you’ll be taken straight to the specific page for your site on Clicky. As you can see from the above example, spikes in traffic are extremely easy to spot, as each bar represents just one hour.

3. Identify Template Files

If you like to tinker with WordPress themes, you have probably found yourself frustrated on more than one occasion by confusion as to what template files generate what pages.

Fortunately, that no longer has to be an issue if you install What The File, which displays the template file in use in the WordPress toolbar:

What The File

Clicking on the filename will take you to the WordPress editor, where you can edit that specific file.

4. Move the Toolbar

Some people are bugged by the toolbar’s appearance at the top of the page. If that is the case, why not move it to the bottom? Just insert this code into your functions.php file (or into Code Snippets):

function fb_move_admin_bar() {
    echo '
'; } // on backend area add_action( 'admin_head', 'fb_move_admin_bar' ); // on frontend area add_action( 'wp_head', 'fb_move_admin_bar' );

And as if by magic, the toolbar will relocate southwards:

Toolbar Bottom

As you can no doubt figure out, you can edit the CSS to make this change on the front end, the back end, or universally.

Code courtesy of WP Engineer.

5. Delete Posts from the Toolbar

The toolbar already allows you to one-click edit posts, but what if you are in a deleting mood? Just add the following code into your functions.php file:

function fb_add_admin_bar_trash_menu() {
  global $wp_admin_bar;
  if ( !is_super_admin() || !is_admin_bar_showing() )
      return;
  $current_object = get_queried_object();
  if ( empty($current_object) )
      return;
  if ( !empty( $current_object->post_type ) && 
     ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && 
     current_user_can( $post_type_object->cap->edit_post, $current_object->ID ) 
  ) {
    $wp_admin_bar->add_menu( 
        array( 'id' => 'delete', 
            'title' => __('Move to Trash'), 
            'href' => get_delete_post_link($current_object->term_id) 
        ) 
    );
  }
}
add_action( 'admin_bar_menu', 'fb_add_admin_bar_trash_menu', 35 );

This will add a “Move to Trash” link in your toolbar:

Move to Trash

You can of course rename the link by changing the “title” variable within the code.

Code courtesy of WP Engineer.

6. Disable Toolbar for All Users Except Administrators

There could be a number of reasons why you would not want to display the toolbar to certain users, but WordPress offers no easy way of setting universal permissions.

Fortunately, manually creating such a permission only involves a scrap of code:

/* Disable WordPress Admin Bar for all users but admins. */
if (!current_user_can('administrator')):
  show_admin_bar(false);
endif;

That’s it! The toolbar will now no longer display for non-admin users.

Code courtesy of WPBeginner.

7. Remove Default Items from the Toolbar

Perhaps you don’t need all of the items on the toolbar, or perhaps you want to make room for items that you do want. Removing default items is easy enough:

function my_edit_toolbar($wp_toolbar) {
	$wp_toolbar->remove_node('wp-logo');
	$wp_toolbar->remove_node('site-name');
	$wp_toolbar->remove_node('updates');
	$wp_toolbar->remove_node('comments');
	$wp_toolbar->remove_node('new-content');
	$wp_toolbar->remove_node('top-secondary');
}

add_action('admin_bar_menu', 'my_edit_toolbar', 999);

The above code, when inserted into your functions.php file, will result in a mysteriously blank toolbar:

Blank Toolbar

All you need to do is remove the line(s) in the code that correspond to the menu item(s) that you want to keep, and you’re set to go!

You may also want to change your login URL or customize login page.

8. Change the Default WordPress Greeting

Although I’ve got total respect for Matt Mullenweg’s Houstonian roots, let’s face it, we don’t all go around greeting people with “Howdy!”, do we?

And yet, that is what we see every day in the toolbar:

WordPress Greeting

It can be a minor irritant for some, or it can come across as somewhat unprofessional if you are creating a site for a client. Either way, changing the default WordPress greeting is a piece of cake:

add_action( 'admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11 );

function wp_admin_bar_my_custom_account_menu( $wp_admin_bar ) {
	$user_id = get_current_user_id();
	$current_user = wp_get_current_user();
	$profile_url = get_edit_profile_url( $user_id );

if ( 0 != $user_id ) {
	/* Add the "My Account" menu */
	$avatar = get_avatar( $user_id, 28 );
	$howdy = sprintf( __('Welcome, %1$s'), $current_user->display_name );
	$class = empty( $avatar ) ? '' : 'with-avatar';

	$wp_admin_bar->add_menu( array(
		'id' => 'my-account',
		'parent' => 'top-secondary',
		'title' => $howdy . $avatar,
		'href' => $profile_url,
		'meta' => array(
		'class' => $class,
	),
) );

}
}

Just change the “Welcome” text within the above code to whatever you like, and you’re set!

It’s recommended to test out these practices in child theme to prevent errors when new theme update rolls in.

Code Courtesy of WP Beginner.

Creative Commons image courtesy of Davide Restivo

Tom Ewer

Tom Ewer is the founder of WordCandy.co. He has been a huge fan of WordPress since he first laid eyes on it, and has been writing educational and informative content for WordPress users since 2011. When he's not working, you're likely to find him outdoors somewhere – as far away from a screen as possible!

14 Comments

  1. Kimsea Sok

    Thanks for sharing…! I have been looking for some way to customize Admin menu and login page. Yesterday I found the way but it is not complete way to customize that thus I skip that ways. Anyway, your one is really great and helpful for me..!

  2. Adel

    I am a big fan of clicky too. Have you succeeded in removing the stats in the admin bar for NON admin users. Apparently, it’s a bug that shows the stats to all users

    1. Tom

      Thanks for sharing Adel!

  3. Matt

    “#7. Remove Default Items from the Toolbar.”

    Beauty eh… completely overlooked this when removing null items (posts, comments, etc) the admin sidebar. That toolbar oversight ended caused me a lot of trouble and confusion as to how they messed up something I thought I fool-proofs. Looks like the fool was me! heh. Thanks for this :) *high-five*

  4. Ding Yang

    Thanks for sharing and your blog looks awesome.

  5. James Nic

    Hey I’m trying to have a customized menu for only a particular set of pages on my website but so far nada. Can you help?

    1. Tom Ewer

      Hey James,

      I’m afraid I’m not that technically skilled :-)

      Cheers,

      Tom

  6. Jacobus

    Man, thanks for the code to move the toolbar from the top to the bottom. This things is always bugging me (especially when you want to see changes you made to an ad stripe at the top of your website which gets totally covered by the toolbar). :-)

    1. Tom Ewer

      No problem Jacobus — I share your pain!

      1. Jacobus

        :-)

  7. shane

    Oooooh, that What The File is so useful. Definitely getting that now! I never thought of making a custom Admin menu for clients but that is also a spectacular idea. Thanks for these!

    1. Tom Ewer

      No problem Shane :)

  8. Fotógrafo de bodas

    Have not found some tips as well written and easy to understand. Some of them are still very úitles me on my Blog. The tip of “Identify Template Files” is the most useful for me, I greatly facilitates the modification of html and php. Thank you very much for sharing!!

    1. Tom Ewer

      No problem :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>