How to Customize the WordPress admin bar?

In WordPress 3.3 version there is a handy admin bar that provides quick access to some Admin features for logged in users.
There are several ways to do customize it by creating functions. Here I will show, how you can customize the admin bar the way you want.

WorPress adds a black menu bar (Admin Bar or Toolbar) at the top of the screen when user is logged in.
This menu bar is also visible even when you are at the front end of the site and provide you a quick links of pages quickly.

WordPress allows us to customize the this bar and it’s possible to add new links (menu items) in that bar or remove or change the existing ones. Using admin_bar_menu or wp_before_admin_bar_render hook we can customize the Admin Bar.
wordpress-admin-bar-vivacity
Removing the WordPress Logo from the admin toolbar

function remove_wp_logo() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
}

add_action( 'wp_before_admin_bar_render', 'remove_wp_logo' );

Disabling the add new content menu from toolbar

function disable_new_content() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('new-content');
}
add_action( 'wp_before_admin_bar_render', 'disable_new_content' );

Adding a new top level menu and two sub menus using admin_bar_menu hook

function custom_admin_bar()
{
global $wp_admin_bar;
//Top menu
$wp_admin_bar->add_menu( array(
'id' => 'my_custom-menu',
'title' => 'Top Menu',
'href' => false
) );
//Sub Menu 1
$wp_admin_bar->add_menu( array(
'id' => 'custom_menu',
'title' => __( 'Google Search' ),
'href' => 'http://google.com/',
'meta'  => array( target => '_blank' ) )
);

// Sub menu 2 to open one of my plugins page
$wp_admin_bar->add_menu( array(
'id' => 'my_plugin-page',
'parent' => 'my_custom-menu',
'title' => 'Settings',
'href' => admin_url('/wp-admin/options-general.php'),
) );
// Sub menu 3 to open facebook link in new window
$wp_admin_bar->add_menu( array(
'id' => 'facebook-page',
'parent' => 'my_custom-menu',
'title' => 'Facebook',
'href' => 'http://facebook.com',
'meta' => array( 'target'=>'_blank' )
) );
}
add_action( 'admin_bar_menu', 'custom_admin_bar' );

Removing the Profile menu from the admin toolbar

function custom_admin_bar_remove() {
global $wp_admin_bar;

/* Remove their stuff */
$wp_admin_bar->remove_menu('my-blogs');
$wp_admin_bar->remove_menu('my-account-with-avatar');
$wp_admin_bar->remove_menu('appearance');
}

add_action('wp_before_admin_bar_render', 'custom_admin_bar_remove', 0);

admin-bar-vivacity
Here are some menu item IDs for top menu links that can be used to customizing the admin bar menu items:

wp-logo: WordPress logo
my-account: Links to your account. The ID depends upon if you have avatar enabled or not.
site-name: Site name with other dashboard items
my-sites : My Sites menu, if you have more than one site
get-shortlink : Shortlink to a page/post
edit : Post/Page/Category/Tag edit link
new-content : Add New menu
comments : Comments link
updates : Updates link
search: Search box

Advertisements

One thought on “How to Customize the WordPress admin bar?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s