How to Completely Disable the WordPress Admin Bar for All Users Except Administrators (2023 Guide)
Are you tired of the WordPress admin bar getting in the way for your non-admin users? Maybe you have a membership site where the admin bar is unnecessarily confusing for members. Or perhaps you‘re developing a client site and want them to experience the site without any extra clutter.
Luckily, there are several ways to selectively disable the WordPress admin bar for specific user roles or all users except administrators. In this comprehensive guide, we‘ll walk through four different methods step-by-step, complete with screenshots, code samples, and expert tips.
But first, let‘s cover the basics – what exactly is the WordPress admin bar and why would you want to hide it?
What is the WordPress Admin Bar?
The WordPress admin bar (also called the toolbar) is the dark gray bar that appears at the top of your screen when you‘re logged into WordPress. It provides quick links to key admin pages like posts, pages, comments, updates and your user profile. For administrators, it also has handy links to create new content, moderate comments, and view the site from the front-end.
While the admin bar can be very convenient for site management, in some cases it‘s unnecessary and even confusing for certain users. Some common reasons to disable it include:
- Membership sites – members don‘t need links to the back-end
- Client sites – clients may find the bar distracting during development
- Minimalist design – the bar can conflict with carefully designed layouts
- Administrators working on content – you may prefer to view the "real" front-end
Whatever your reasoning, selectively disabling the WordPress admin bar is relatively simple. Here are four methods to accomplish it, starting with the simplest and ending with the most advanced and customizable.
Method 1: Disable the Admin Bar for Individual Users
If you only have a handful of users who don‘t need the admin bar, the quickest solution is to simply edit their user profiles one at a time. Here‘s how:
- From your WordPress dashboard, go to Users > All Users
- Hover over the user you want to edit and click "Edit" under their name
- Under "Personal Options", uncheck the box for "Show Toolbar when viewing site"
- Click "Update User" at the bottom of the screen to save the change
Repeat this for each user who shouldn‘t see the admin bar. This is fine for just a few users, but it gets tedious fast if you have a lot of users. In that case, one of the other methods below would be much more efficient.
Method 2: Disable the Admin Bar for All Non-Admins with Code (functions.php)
To hide the admin bar for all users except administrators in one fell swoop, you can paste a code snippet into your theme‘s functions.php file. This is a good option if you‘re comfortable editing WordPress files and want to solve it with a few lines of code.
Important: Before editing your theme files, it‘s always a good idea to make a backup in case something goes wrong. You can use a plugin like UpdraftPlus or manually copy your theme folder via FTP.
Once you have a backup, here‘s how to add the code in functions.php:
- From your WordPress dashboard, go to Appearance > Theme Editor
- In the right-hand sidebar, click on "functions.php" under "Theme Files"
- Paste the following code at the very end of the file:
add_action(‘after_setup_theme‘, ‘remove_admin_bar‘);
function remove_admin_bar() {
if (!current_user_can(‘administrator‘) && !is_admin()) {
show_admin_bar(false);
}
}
4. Click "Update File" to save the changes
This code snippet first checks if the current user is an administrator, and if they‘re viewing the admin dashboard. If not, it disables the admin bar by setting `show_admin_bar` to `false`.
After saving, visit your site and log in as a non-admin user to make sure it worked. The admin bar should be hidden on the front-end. Administrators will still see it everywhere.
The advantage of this method is that it‘s just a few lines of code and instantly hides the bar for all your non-admin users. However, editing the functions.php file directly can be risky – one mistake can bring down your whole site. If you‘re not totally comfortable with code, you may want to try a plugin instead.
Method 3: Selectively Disable Admin Bar with a Plugin (No Code Required)
If you‘d rather not mess with code, you can use a plugin like Hide Admin Bar Based on User Roles to selectively disable the WordPress admin bar without any technical know-how required. This is a good choice if you want a simple on/off toggle for the admin bar based on existing user roles.
To set it up:
1. Install and activate the free Hide Admin Bar Based on User Roles plugin
2. Go to Settings > Hide Admin Bar Settings in your WordPress dashboard
3. Check the box under "Hide Admin Bar for" for each user role where you want to disable the admin bar (e.g. "Subscriber" and "Customer" but not "Administrator")
4. Click "Save Changes"
That‘s it! The plugin will now hide the admin bar for any users with the roles you selected, but keep it for administrators and any other unchecked roles. It‘s a simple, code-free solution.
Of course, the drawback is less flexibility compared to custom code snippets. You can only toggle the bar on/off for existing user roles – you can‘t set more custom rules like hiding it only on the front-end. But if existing roles meet your needs, the plugin is a great option.
Method 4: Hide the Admin Bar Everywhere with Code (Admin Users Too)
Want to hide the WordPress admin bar everywhere, even for administrators? You can do that too with another simple code snippet. This is handy if you find the admin bar distracting when working on content and prefer the "real" front-end view.
To set it up, add this code to your functions.php file using the same process as Method 2 above:
add_filter(‘show_admin_bar‘, ‘__return_false‘);
This will completely disable the admin bar everywhere, for all users (yes, including administrators), as long as they are not on an admin page (/wp-admin/). It provides a totally clean view of your site‘s front-end.
The advantage is simplicity – just a single line of code. But remember, this will affect your administrator account too when not in the WordPress dashboard, so use it carefully. You can always comment out or delete the code to bring the admin bar back.
Bonus Tips & Tricks
Here are a few more things to keep in mind when customizing the WordPress admin bar:
- If you hide the admin bar using PHP code snippets, the "Show Toolbar when viewing site" option will still appear in users‘ profiles. But it will be ignored based on the rules in your code.
- When you disable the admin bar for certain users, make sure they have another way to access key pages they need. For example, make sure members have clear navigation to their account page.
- If you‘re not comfortable editing functions.php directly, you can achieve the same result using a plugin like Code Snippets. It lets you add the PHP code in a more user-friendly interface.
- You can take customization even further with CSS tweaks. For example, to hide the admin bar only on mobile devices, use a media query in your stylesheet like:@media screen and (max-width: 600px) {
display: none;}
}
Selectively disabling the WordPress admin bar is a great way to simplify the experience for certain users and create a cleaner front-end view. Whether you have a membership site, client site, or just want to minimize distractions, you have several good options to hide the toolbar.
For just a few users, editing their profiles directly is the simplest solution. With a larger user base, adding a few lines of code to functions.php can instantly hide it for non-admins. If you‘re not comfortable with code, a plugin can also toggle it based on user roles without any technical know-how.
Whichever method you choose, just remember to test it thoroughly and make sure your users still have easy access to any key pages they need. With a bit of thoughtful customization, you can create a cleaner, simpler WordPress experience for everyone.