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.

Video Tutorial

If you don’t like the video or need more instructions, then continue reading.

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 experts 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. Alexander Pardo says:

    Thank you very much ! A very simple and clean solution. :)

  2. Jason A. Churchill says:

    I’m not well-read in editing the functions.php file. My first two attempts resulted in syntax error messages.

    Where exactly should I place this code in the functions.php file?

    • WPBeginner Support says:

      At the end. If your functions.php file ends with ?> then you need to paste the code just before it.

  3. Terry Hale says:

    Thanks so much for this! No plugins, nice, clean, simple.

  4. WPBeginner Staff says:

    WordPress admin bar is displayed only for logged in users.

  5. Bhris says:

    Great straight-to-the-point tutorial.

    Is there a version of the code that will block all non-users. That is, visitors to the site won’t see the bar, while all logged-in users would?

  6. Shashi says:

    I was trying to do what what was mentioned in the article and it did not work. I used the following instead which did the trick from me:

    if ( ! current_user_can( ‘manage_options’ ) ) {
    show_admin_bar( false );
    }

    The above was mentioned in the wordpress codex: http://codex.wordpress.org/Function_Reference/show_admin_bar

  7. kim04099 says:

    Thank You!!

  8. Che Boielle says:

    Fastest fix to an odd issue I’ve ever found and implemented. Great explanation simple to follow instructions. Thanks guys, will be book marking your site.

  9. Manthan says:

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

  10. Ryan McGovern says:

    Thanks for the code snippet!

  11. Anup says:

    Why not simply do this for any specific user.

  12. Róger Marroni says:

    Great job man!

    thank you very much!

  13. Mega says:

    I tried and my site is black.

  14. Etienne says:

    Perfect piece of code… Thanks a lot!

    Cheers

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

  16. meef says:

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

    Thanks

  17. Prem says:

    Finally I got the answers Thank you

  18. 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)

  19. 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.

  20. Raman says:

    Thanks for posting it was useful.

  21. 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?

  22. 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.

  23. 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.

  24. vikas says:

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

  25. Rajat says:

    Thx syed it just worked perfectly

  26. Bongo says:

    Thanks for this, it helped me a lot

  27. 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

  28. Rajiv says:

    Hi,

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

    Please help.

  29. 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.

  30. Adrian says:

    Thanks!

  31. Fabio Santos says:
  32. 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?

  33. 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”.

  34. Cristian B. says:

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

  35. niki says:

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

  36. 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.

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

  38. Adam says:

    worked …
    Thanks a lot

  39. 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

  40. 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

  41. 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.

  42. Sally says:

    Excellent post thanks so much!

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

    Sally :) x

  43. Corey Freeman says:

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

  44. 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!

  45. 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

  46. 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.