BeastThemes

Black Friday Sale

Get 25% Discount on all our products by using BFRIDAY25 Coupon Code.

4 Ways to Hide Admin Bar based on User Roles in WordPress

hide-admin-bar

Do you want to easily hide admin bar based on user roles in WordPress?

By default, you’ll easily disable the WordPress admin bar for any user from the dashboard. But this method can take time if you’ve got tons of registered users on your site.

In this article, we’ll show you ways 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 within the WordPress admin area also like all other pages once you are logged in.

hide admin bar based on user roles
This is my site ( https://beastthemes.com/ ) frontend view as a logged in user.

The WordPress admin toolbar contains useful shortcuts to different WordPress sections. The shortcuts available within the admin bar change supported a users’ role and permissions in WordPress.

However, when viewing the general public pages on the front-end of your website, the admin bar is often a touch distracting. it’s going to also affect your website’s design and user experience.

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

Method 1. Disabling The WordPress Admin Bar for Any User

WordPress allows each user to hide admin bar based on user roles by simply editing their user profile. As a site owner, you’ll also edit other user’s profiles and disable the admin bar for them.

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

Simply attend the Users » All Users page then click on the ‘edit’ link for any user you would like to disable the admin bar for.

user edit view

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

user edit view second

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.

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

Method 2. Disable Admin Bar for All Users Except Administrators Using Code

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

Simply add the following code to your theme’s functions.php file

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

This code checks if the present user isn’t an administrator, and that they aren’t viewing the admin dashboard. If both conditions match, then it’ll hide admin bar based on user roles.

Don’t forget to save lots of your changes and check your website to form sure everything is functioning fine.

Method 3. Disable Admin Bar for All Users Including Admins

What if you wanted to hide admin bar based on user roles including yourself and the other administrator on your site?

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

Simply add the following code to your theme’s functions.php file.

/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );

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 method allows you to quickly hide admin bar based on user roles in WordPress.

First, you need to install and activate the Hide Admin Bar Based on User Roles 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.

hide admin bar based on user roles

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

We hope this article helped you learn how to hide admin bar based on user roles in WordPress.