How to Hide WordPress Admin Bar for All Users except Administrators

Recently, we’ve seen how you can add custom links to WordPress admin bar. But sometimes you may want to disable the admin bar for all the users on your WordPress site including or excluding the site administrator. The reasons for this include but not limited to building a membership site, to restrict access to the admin bar for certain users, etc.

Now, you might be thinking of the option in the user profile settings page that enables each user to hide the admin bar while viewing the site. But it may not be that useful as it only hides the admin bar while viewing the front-end of your site and you have to manually change the setting for each and every user.

Even if you’ve managed to change the setting for each user, they can easily re-enable the admin bar from the profile page. So no matter what the reason is, you can easily disable or hide WordPress admin bar for all users except administrators.

Hide WordPress Admin Bar for All Users

As I said before, you can hide WordPress admin bar for all users including the administrator. To start off, open your FTP client and then log in to your account. Once logged in, navigate to your current theme folder and then open the file functions.php.

hide-wordpress-admin-bar-functions-file

After opening the file, copy and paste the below code snippet at the end of the file and you are good to go.

// Disable WordPress Admin Bar for All Users
show_admin_bar(false);

From this point forward, the WordPress admin bar is hidden from all users including the administrators.

Note: since the code snippet shared above (and below) isn’t related to your theme functionality, you can also add it to the site specific plugin.

Hide WordPress Admin Bar for All Users except Administrators

Alternatively, you can also hide WordPress admin bar for all users except administrators. To do that simply copy and paste the below code in the functions.php file and you are good to go.

// Hide Admin Bar for All Users Except Adminministrators
function bs_hide_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}
add_action('after_setup_theme', 'bs_hide_admin_bar');

In case you are wondering, all the above code does is that it checks if the user is an administrator, if not, the admin bar will be hidden or disabled.

If you don’t want to mess with file and code snippets, then use the free pluginĀ Hide Admin Bar from Non-Admins. The plugin essentially has the same code snippet and once you activate the plugin, the WordPress admin will be hidden from all non-admin users. Being a simple plugin, it doesn’t have any settings page whatsoever.

That’s all there is to do and hopefully that helps. Do comment below sharing your thoughts and experiences about using the above methods to disable or hide WordPress admin bar for all users including or excluding the administrator.

4 Comments

    1. Hi,

      I just checked the code shared in the article and it works just fine. In fact, your suggestion also works as it should.

      However, if the code doesn’t work for some users then they can always replace

      show_admin_bar(false);

      with

      add_filter('show_admin_bar', '__return_false');

      Thanks for the suggestion. See you around.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.