How to Customize the WordPress admin bar?

Sharing is caring!

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
[code]
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’ );
[/code]

Disabling the add new content menu from toolbar
[code]
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’ );
[/code]

Adding a new top level menu and two sub menus using admin_bar_menu hook
[code]
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’ );
[/code]

Removing the Profile menu from the admin toolbar
[code]
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);
[/code]

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

2 thoughts on “How to Customize the WordPress admin bar?

Leave a Reply

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

Got Project on mind? Let's ConnectContact Us

Secured By miniOrange