Taking Control of WordPress 3.8 Admin Bar

What is WordPress Admin Bar?

WordPress admin bar was introduced in WordPress 3.1. The purpose of the WordPress Admin Bar was to connect the backend (dashboard) of a WordPress to the Live. It always shows up right below the browser address bar and looks somewhat like below image:

wordpress admin nav

The WordPress Admin Bar helps webmasters switch to the basic features of the Dashboard directly from their WordPress front-end. Although the presence of the WordPress Admin Bar is a boon, most webmasters don’t like the presence of anything sitting on our sites, I guess the 1-click access to the WordPress Dashboard isn’t what everybody is comfortable with.

Why an Admin Bar?

“First step towards a front-end editor” – Matt Mullenweg, the man who gave birth to WordPress.

The WordPress admin bar has been tagged as the first step towards bringing the WordPress editor right into your site and moving it out of the Dashboard. It will be interesting to see how WordPress incorporates the Dashboard features into our blog’s front end without making it tacky. For now, Admin Bar is here and needs a lot of improvements.

Remove Links from the WordPress Admin Bar

There is lot of things, That you want to remove from the WordPress Admin Bar. Before we start with adding new links to the WordPress Admin Bar (which is a bit complex) we will start removing remove links from the WordPress Admin Bar.

Remove Author Name Menu or just sub-parts

The very first drop down menu in the WordPress Admin Bar is the name of author. It will have two options – Edit Profile and Logout. You can remove this complete menu (or just the sub-parts) by inserting the below code in

functions.php

of your current theme:

<?php

function editMyAdminBar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('my-account-with-avatar');
    // This will hide the menu item with author name.

    $wp_admin_bar->remove_menu('edit-profile');
    // This will remove the sub-part "Edit My Profile".

    $wp_admin_bar->remove_menu('logout');
    // This will remove the sub-part "Logout".
}

add_action('wp_before_admin_bar_render', 'editMyAdminBar');
?>

Next is the Dashboard link in the WordPress Admin Bar. Insert below code in

functions.php

:

<?php

function editMyAdminBar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('dashboard');
}

add_action('wp_before_admin_bar_render', 'editMyAdminBar');
?>

Next is the Add New link which has lot of sub items too and we have some other menus in our admin bar. Use the below code to remove all or sub items:

<?php

function editMyAdminBar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('new-content');
    // This removes the complete menu “Add New”. You will not require the below “remove_menu” if you using this line.

    $wp_admin_bar->remove_menu('new-post');
    // This will hide the menu item “Post”.

    $wp_admin_bar->remove_menu('new-page');
    // This will hide the menu item “Page”.

    $wp_admin_bar->remove_menu('new-media');
    // This will hide the menu item “Media”.

    $wp_admin_bar->remove_menu('new-link');
    // This will hide the menu item “Link”.

    $wp_admin_bar->remove_menu('new-user');
    // This will hide the menu item “User”.

    $wp_admin_bar->remove_menu('new-theme');
    // This will hide the menu item “Theme”.

    $wp_admin_bar->remove_menu('new-plugin');
    // This will hide the menu item “Plugin”.

    $wp_admin_bar->remove_menu('comments');
    // This will hide the menu “Comments”.

    $wp_admin_bar->remove_menu('appearance');
    // This removes the complete menu “Appearance”. You will not require the below “remove_menu” if you using this line.

    $wp_admin_bar->remove_menu('new-themes');
    // This will hide the menu item “Themes”.

    $wp_admin_bar->remove_menu('new-widgets');
    // This will hide the menu item “Widgets”.

    $wp_admin_bar->remove_menu('new-menus');
    // This will hide the menu item “Menus”.

    $wp_admin_bar->remove_menu('updates');
    // This will hide the menu “Updates”.

    $wp_admin_bar->remove_menu('get-shortlink');
    // This will hide the menu “Shortlink”.
}

add_action('wp_before_admin_bar_render', 'editMyAdminBar');
?>

Now we are moving to Add Links to WordPress Admin Bar

Most of sites have a link to the homepage, if you want to add one then you can use the below code in your

functions.php

:

<?php
function add_new_item_to_adminbar() {
    global $wp_admin_bar;
    $wp_admin_bar->add_menu(array(
        'id' => 'view-site', //the view-site ID that refers to what we are doing.
        'title' => __('Visit Site'), //the anchor text that links to homepage.
        'href' => site_url())); //the homepage URL to which the anchor text will connect.
}

add_action('wp_before_admin_bar_render', 'add_new_item_to_adminbar');
?>

Add sub-menu item in “Add New” menu

This will be interesting. We will add a new item inside a menu that already exists. The below code will add a My Media option in the menu Add New.

<?php
function add_submenu_to_adminbar() {
    global $wp_admin_bar;
    $wp_admin_bar->add_menu( array(
        'parent' => 'new-content',
        // new-content is the ID for “Add New” menu so we use it as parent ID.
        
        'id' => 'new_media', 
        // You can add any value here as you are adding something very new here.
        
        'title' => __('Media'), // The anchor text.
        
        'href' => admin_url( 'media-new.php') 
        // name of file to which you will link to.
        ));
}
add_action( 'wp_before_admin_bar_render', 'add_submenu_to_adminbar' );
?>

Hope! this is a good tutorial for all my blog reader, If any one have any query’s and error please put your comments bellow.

Leave a Reply

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