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('init', '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);







To avoid the blank space where the admin bar was, call the function in the “after_setup_theme” action instead of “init”.
Really nice code. Are here also a fix to the blank bar that many here complains?
Fantastic! Except I also have the blank space visible where the admin bar would be. Does anyone have a fix for this?
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.
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?
worked …
Thanks a lot
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
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
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
Agreed. Just updated the code to make it into a function, and then adding it in via action.
Excellent post thanks so much!
Took me under a minute and the bar was gone… forever… truly grateful.
Sally
x
Thanks to this I have one less plugin bloating my site. Woo!
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!
Hi Guys,
Just found this bit of code and it worked perfect for my site…
Thanks so much
Cheers
James
AKA The Fitness Blogger
Nice. For Superadmins in a Multisite install it would read like if(!current_user_can(‘manage_network’)) //etc.