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
Elegant Themes
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 »

Comments

  1. Mega says:

    I tried and my site is black.

  2. Etienne says:

    Perfect piece of code… Thanks a lot!

    Cheers

  3. Nathan Jansen says:

    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);
    }
    }

  4. meef says:

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

    Thanks

  5. Prem says:

    Finally I got the answers Thank you

  6. Paw Pet Directory says:

    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)

  7. Cory says:

    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.

  8. Raman says:

    Thanks for posting it was useful.

  9. Naveen says:

    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?

  10. Subodh says:

    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.

  11. Loralee says:

    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.

  12. vikas says:

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

  13. Rajat says:

    Thx syed it just worked perfectly

  14. Bongo says:

    Thanks for this, it helped me a lot

  15. Andy Wagstaff says:

    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

  16. Rajiv says:

    Hi,

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

    Please help.

  17. Ken Shoufer says:

    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.

  18. Adrian says:

    Thanks!

  19. Fabio Santos says:
  20. Nate says:

    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?

  21. Tanner Moushey says:

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

  22. Cristian B. says:

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

  23. niki says:

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

  24. Marlita Hill says:

    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.

  25. Steve says:

    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? ;-)

  26. Adam says:

    worked …
    Thanks a lot

  27. Nick Cokas says:

    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

  28. Toby Couchman says:

    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

  29. Mark Coleman says:

    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

    • Editorial Staff says:

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

  30. Sally says:

    Excellent post thanks so much!

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

    Sally :) x

  31. Corey Freeman says:

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

  32. Delton Childs says:

    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!

  33. James Davis says:

    Hi Guys,

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

    Thanks so much

    Cheers

    James

    AKA The Fitness Blogger

  34. glueckpress says:

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

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.