Paulund
2012-01-22 #wordpress

How To Remove Links From Wordpress Admin Bar

In Wordpress 3.3 they have upgraded the admin bar with new icons and new options.

But what if you don't want some users to have access to some of the things on the admin bar, you need to try to remove the links. To remove the links you just need to add the following function to your functions.php file and add a new action into the wp_before_admin_bar_render function.


function remove_admin_bar_links() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('wp-logo');          // Remove the Wordpress logo
    $wp_admin_bar->remove_menu('about');            // Remove the about Wordpress link
    $wp_admin_bar->remove_menu('wporg');            // Remove the Wordpress.org link
    $wp_admin_bar->remove_menu('documentation');    // Remove the Wordpress documentation link
    $wp_admin_bar->remove_menu('support-forums');   // Remove the support forums link
    $wp_admin_bar->remove_menu('feedback');         // Remove the feedback link
    $wp_admin_bar->remove_menu('site-name');        // Remove the site name menu
    $wp_admin_bar->remove_menu('view-site');        // Remove the view site link
    $wp_admin_bar->remove_menu('updates');          // Remove the updates link
    $wp_admin_bar->remove_menu('comments');         // Remove the comments link
    $wp_admin_bar->remove_menu('new-content');      // Remove the content link
    $wp_admin_bar->remove_menu('w3tc');             // If you use w3 total cache remove the performance link
    $wp_admin_bar->remove_menu('my-account');       // Remove the user details tab
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

To enhance this function more you can add some logic in to only remove certain links to different user roles. The follow will remove the updates, comments, new content and performance links from the admin bar if the user isn't the admin user. On most Wordpress blogs the admin user has the User ID of 1 so you can apply the following snippet.


function remove_admin_bar_links() {
    global $wp_admin_bar, $current_user;
    
    if ($current_user->ID != 1) {
        $wp_admin_bar->remove_menu('updates');          // Remove the updates link
        $wp_admin_bar->remove_menu('comments');         // Remove the comments link
        $wp_admin_bar->remove_menu('new-content');      // Remove the content link
        $wp_admin_bar->remove_menu('w3tc');             // If you use w3 total cache remove the performance link
        $wp_admin_bar->remove_menu('my-account');       // Remove the user details tab
    }
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );