Ali The Expert

Logo

How to Disable WordPress Admin Bar for All Users Except Administrators

Do you want to easily disable the admin bar in WordPress?

By default, you can easily disable the WordPress admin bar for any user from the dashboard. But this method can take time if you have a lot of registered users on your site. 

In this article, we’ll show you how to disable the WordPress admin bar for all users except administrators.

What is WordPress Admin Bar?

By default, WordPress displays an admin bar on the top for all logged-in users. This toolbar is visible in the WordPress admin area as well as all other pages when you are logged in.
The WordPress admin toolbar contains useful shortcuts to different WordPress sections. The shortcuts available in the admin bar change based on a user’s role and permissions in WordPress.

However, when viewing the public pages on the front-end of your website, the admin bar can be a bit distracting. It may also affect your website’s design and user experience. 

Luckily, there are multiple ways to easily disable the WordPress admin bar for all users except administrators.

Method 1. Disabling The WordPress Admin Bar for Any User (Manually)

WordPress allows each user to disable the admin bar by simply editing their user profile. As a site owner, you can also edit other users’ profiles and disable the admin bar for them. 

If you want to disable the admin bar for any particular user in WordPress, you’ll need to edit their user profile. 

Simply go to the Users » All Users page and then click on the ‘edit’ link for any user you want to disable the admin bar for. 

This will bring you to the user profile editor page. From here, uncheck the box next to the ‘Show toolbar when viewing site’ option.

Scroll down and click the ‘Update User’ button to save your changes. 

This will disable the admin bar for that particular user when they visit the website.

If you have a handful of users, then you can go ahead and manually disable the admin bar for all of them. However, if you run a membership site with a lot of users, then this method wouldn’t work. 

Luckily, there are other ways to quickly disable the admin bar for all users except administrators.

This method requires you to add code to your WordPress theme files. If you have not done this before, then check out our guide on how to copy and paste code snippets in WordPress.  

You need to add the following code to your theme’s functions.php file or a code snippets plugin.

  1. add_action(‘after_setup_theme’, ‘remove_admin_bar’);
  2. function remove_admin_bar() { 
  3. if (!current_user_can(‘administrator’) && !is_admin()) { 
  4. show_admin_bar(false);  
  5. }

This code checks if the current user is not an administrator, and they are not viewing the admin dashboard. If both conditions match, then it will disable the WordPress admin bar. 

At WPBeginner, we always recommend using the WPCode code snippets plugin to add custom code in WordPress.

WPCode makes it easy to add code snippets in WordPress without having to edit your theme’s functions.php file. That way, if you ever update or change your theme, all of your custom code functions will be saved.

Plus, WPCode comes with smart code snippet validation that helps you prevent common code errors that could break your site. 

The first thing you need to do is install and activate the free WPCode plugin. If you need help, follow our step by step guide on how to install a WordPress plugin. 

Once the plugin is activated, go to Code Snippets » Add Snippet from your WordPress admin dashboard.

On the next screen, find the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.

Next, add a title for your custom code. Then, simply paste the copied code snippet from above into the ‘Code Preview’ box.  

You also need to choose ‘PHP Snippet’ from the dropdown list on the right.

After that, scroll down the page to the ‘Insertion’ section. 

Here, you can keep the default ‘Auto Insert’ method. This will automatically insert and execute the code in the proper place.

Finally, toggle the switch from ‘Inactive’ to ‘Active’. 

Then click the ‘Save Snippet’ button.

That’s it! Just remember to check your website to make sure everything is working fine.

Method 3. Disable Admin Bar for All Users Including Admins Using Code

What if you wanted to disable the admin bar for all users including yourself and any other administrator on your site? 

You can do this by modifying the code we showed earlier. 

Simply add the following code to the WPCode plugin by following the same steps as above.

  1. /* Disable WordPress Admin Bar for all users */
  2. add_filter( ‘show_admin_bar’, ‘__return_false’ );

To make it even easier, WPCode has this exact code snippet in its built-in Snippet Library. 

Go to Code Snippets » Library and search for the ‘Disable The WP Admin Bar’ code snippet. Then, click the ‘Use snippet’ button. 

The plugin will automatically add the code, give the code a title, choose the correct insertion method, and even add tags to help you identify it.
All you need to do now is toggle the switch from ‘Inactive’ to ‘Active’ and click the ‘Save Snippet’ button.
This code will disable the admin bar for all users when viewing the public pages of your website. All users will still be able to see the toolbar inside the WordPress admin dashboard.

Method 4. Disable Admin Bar for All Users Except Admins with a Plugin

This is another method that allows you to quickly disable the WordPress admin for all users.

First, you need to install and activate the Hide Admin Bar Based on User Roles plugin. For more details, see our step by step guide on how to install a WordPress plugin. 

Upon activation, go to the Settings » Hide Admin Bar Settings page. From here, check the boxes next to the user roles where you want to disable the admin bar.

Don’t forget to click on the ‘Save Changes’ button to store your settings.  

We hope this article helped you learn how to disable the WordPress admin bar for all users except administrators. You may also want to see our ultimate WordPress security guide and our comparison of the best WordPress page builder for creating custom page layouts without any code.