Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Disable WordPress Admin Bar for All Users Except Administrators

Last updated on by
Follow WPBeginner on YouTube
How to Disable WordPress Admin Bar for All Users Except Administrators

Recently while working on a membership site, we had to create multiple level of users. We did not want the users to have access to the WP-Admin panel because it was not customized for their experience. Rather we had put everything necessary (such as edit profile page), user dashboard etc, on the front-end. While S2 Membership Plugin allowed for us to disable wp-admin access for all users except for admins, there was no option to disable the admin bar by default. In this article, we will show you how to disable WordPress admin bar for all users except for Administrators.

Disable Admin Bar for All Users Except for Administrators

Paste this code in your theme’s functions.php file or your site-specific plugin.

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

Disable Admin Bar for All Users

If you want to disable it for all users, then simply put use this code in your theme’s functions.php file or your site-specific plugin.

/* Disable WordPress Admin Bar for all users but admins. */
  show_admin_bar(false);

Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Manthan

    Thanks, Its the easiest way found..!!!

  • http://www.rayanzenner.com Ryan McGovern

    Thanks for the code snippet!

  • Mega

    I tried and my site is black.

  • Etienne

    Perfect piece of code… Thanks a lot!

    Cheers

  • Nathan Jansen

    Use this if you want this only for a certain role

    function remove_admin_bar() {
    $user = wp_get_current_user();

    if (in_array(‘subscriber’, $user->roles)) {
    show_admin_bar(false);
    }
    }

  • meef

    Godbless You. Answers to my problem always come from you post.

    Thanks

  • Prem

    Finally I got the answers Thank you

  • Paw Pet Directory

    I used this on my directory for my customers but the bar will not go away for them. I am using 3.8 with AppThemes Vantage Theme (Latest)

  • Cory

    This is one of those things that, because it’s such a small customization, I’d hate to use a plugin for. So being able to throw this short piece of code into my child theme’s functions.php made me super happy. Thanks so much far sharing! Works like a charm.

  • Raman

    Thanks for posting it was useful.

  • Naveen

    I have added this code it is working fine, but if a user takes meta there is an option yo view the admin, if i click on this the admin page can see, how to avoid this, i dont want to give admin panel to the users, a user can edit the url and give /wp-admin also he can see the admin, i dont want both what will do for this?

  • Subodh

    Admin bar is hidden but now how can a user log out?
    I am using bbpress forum and a plugin for users to log in via their Facebook account to join forum. But find no option for logging out.

    • http://www.wpbeginner.com/ WPBeginner Support

      A link to the logout or login can be provided into sidebar or menus. WordPress comes with a default widget called meta which has login/logout link. Or you can add one to your site’s navigation menus. See our guide on how to show different menus to logged in users

  • Loralee

    Thanks for the great tutorial. I thought it didn’t work – and then silly me I hadn’t followed the last step to activate my new plugin!! Thanks so much for this! So much better than installing multiple new plugins.

  • vikas

    Thanks mate….u were really helpful…
    tc :-)

  • Rajat

    Thx syed it just worked perfectly

  • Bongo

    Thanks for this, it helped me a lot

  • Andy Wagstaff

    I have an area of my site that requires log-in registration.
    I have made the admin bar “autohide” by requiring a plug-in, I don’t want to entirely disable it, as I need the abiity to change password, but is there any way of removing items from the bar for users? I don’t want the site name,WP logo or the theme extensions options on the left hand side.

    Is this possible? I am sure it is, but I can’t work it out!!

    Ta!! Really handy site by the way

    Andy

  • Rajiv

    Hi,

    I want to disable BP Admin Bar for Logged Out Users.

    Please help.

  • Ken Shoufer

    Hello,

    Your code worked fine when I tried it locally on my computer, but when I tried it on a fresh WordPress install on my host server it would not let me log out. When I tried to log out, the address showing was “http://www.ken-shoufer.com/wordpress1/wp-login.php?action=logout&_wpnonce=9e7f51a307″.

    I’m not sure what is wrong.

    • http://www.wpbeginner.com Editorial Staff

      That’s weird because we have it running on our live site.

  • Adrian

    Thanks!

  • Fabio Santos
  • Nate

    i am trying to disable the W logo on the top left, the “My Sites” menu and the dashboard link on a buddypress multisite install. I want to keep the right side functional which shows the links to their buddypress profile settings. How can I achieve this?

  • Tanner Moushey

    To avoid the blank space where the admin bar was, call the function in the “after_setup_theme” action instead of “init”.

    • Cristian O. Balan

      Really perfect, thanks a lot!

    • Will

      Thank you so much! This worked perfectly and resolved several hours of head-scratching.

  • Cristian B.

    Really nice code. Are here also a fix to the blank bar that many here complains?

    • David

      Hi,
      To avoid the blank, just instead of :
      add_action(‘init’, ‘remove_admin_bar’);
      use:
      add_action(‘after_setup_theme’, ‘remove_admin_bar’);

      • Cristian O. Balan

        Thanks a lot man!

  • niki

    Fantastic! Except I also have the blank space visible where the admin bar would be. Does anyone have a fix for this?

  • Marlita Hill

    Hello. Thank you for this. How would I write the code if I only want the bar accessible to admin and contributors? I still do not want the contributors to have admin access to my backend.

  • Steve

    Well… it removes the admin bar but it´s still occupying the space meaning there´s too much space up there now. I´m not sure it´s supposed to be that way? ;-)

  • Adam

    worked …
    Thanks a lot

  • Nick Cokas

    Add the code and worked perfect. However, the user still sees a white space above were the toolbar existed before. Any ideas to remove that.

    Thanks

  • Toby Couchman

    Did you use a plugin to place all the necessary user stuff on the frontend?

    My team recently built a site with similar requirements and I’d love to compare the processes.

    Cheers
    Toby

  • Mark Coleman

    Do not pass a role name to current_user_can(), as this is not guaranteed to work correctly. from
    http://codex.wordpress.org/Function_Reference/current_user_can

    just FYI

    • http://www.wpbeginner.com Editorial Staff

      Agreed. Just updated the code to make it into a function, and then adding it in via action.

  • Sally

    Excellent post thanks so much!

    Took me under a minute and the bar was gone… forever… truly grateful.

    Sally :) x

  • Corey Freeman

    Thanks to this I have one less plugin bloating my site. Woo!

  • Delton Childs

    This is an awesome post. short, to the point and contained a useful snippet! Thank you so much!

    I’m using the S2Member plugin also, I was very concerned about compatibility issues with plugin based solutions because of the various s2Membership Levels. This solutions is working wonderfully for me.

    Thanks Again!

  • James Davis

    Hi Guys,

    Just found this bit of code and it worked perfect for my site…

    Thanks so much

    Cheers

    James

    AKA The Fitness Blogger

  • glueckpress

    Nice. For Superadmins in a Multisite install it would read like if(!current_user_can(‘manage_network’)) //etc.