Want to hide the WordPress admin bar? This toolbar, visible to logged-in users, offers quick access to site features.
However, subscribers seldom need it, and for developers, it can disrupt design. So, in this article we will show you how to disable the WordPress admin bar.
Key Takeaways
- You can hide the admin bar for everyone or just specific roles easily using the “Hide Admin Bar on User Roles” plugin
- Alternatively, you can add the following line of code to your website via the “Code Snippets” plugin: add_filter( ‘show_admin_bar’, ‘__return_false’ );
How to hide WordPress admin bar
There are two easy ways to hide the WordPress admin bar. Both require installing a plugin. The difference is that the first one doesn’t involve code at all, while the second lets you add code snippets to your website from a user-friendly editor. We will show you both methods.
But before we proceed, we strongly recommend that you take a backup of your entire website. In this section, you will need to go to the backend of your website and modify files which is risky business. Even installing a new plugin is not without risk as new installations are known to crash websites. So, take a backup of your website right away. If things ever go south, you can quickly restore your website back to normal. That said, hiding your WordPress admin bar isn’t a particularly dangerous operation, so this is more about being prepared for the future.
Alternatively, you can also carry out the operation on a staging site without risking the live website.
Now, let’s begin:
1. Hiding the admin bar for all users
The admin bar can be an annoying presence. So, if you want to disable it for all your users, then here’s how to do it:
a) Using a plugin
Install and activate the “Admin and Site Enhancements” plugin. Then go to Tools → Enhancements. Select Admin Interface and enable Hide Admin Bar. Expand the section and check all the user roles to hide the admin bar for all users. Click Save Changes.
b) Using code
If you prefer a more technical way to hide the WordPress admin bar, adding code snippets to your site is a good alternative. To do this, you need to install the “Code Snippets” plugin.
After installing the plugin, go to Snippets → Add New in your dashboard menu and insert the following code snippet:
/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );
Here’s what it looks like on our website:
Once you click Save Changes, the admin bar won’t show up again for any users in the dashboard or on the front end. You can see for yourself that the bar is missing by checking the dashboard and previewing the website.
That’s it. You have now hidden the WordPress toolbar for all users!
2. Hiding the admin bar for a specific user
This is easy. You can hide the admin bar for specific users from the dashboard.
Go to Users → All Users. Select the user you want to hide the admin bar for. Uncheck the Show Toolbar when viewing site option and save changes.
3. Hiding the admin bar for a user role
Certain user roles (like subscribers, customers, etc.) don’t have to have access to the WordPress dashboard. To discourage them from accessing the dashboard, you can hide the WordPress admin bar based on user roles. Here’s how to hide WordPress admin bar for a certain user role:
a) Using a plugin
Install and activate the “Admin and Site Enhancements” plugin.
Go to Tools → Enhancements, select Admin Interface, and enable Hide Admin Bar. Expand the options and check the user roles you want to prevent from accessing the WordPress dashboard and save your settings.
b) Using code
The second method involves adding a code snippet to your website. To do so, install and activate the “Code Snippets” plugin.
Go to Snippets → Add New in your dashboard menu and insert this code in the editor:
function check_current_user_role( $roles ) {
/*@ Check user logged-in */
if ( is_user_logged_in() ) :
/*@ Get current logged-in user data */
$user = wp_get_current_user();
/*@ Fetch only roles */
$currentUserRoles = $user->roles;
/*@ Intersect both array to check any matching value */
$isMatching = array_intersect( $currentUserRoles, $roles);
$response = false;
/*@ If any role matched then return true */
if ( !empty($isMatching) ) :
$response = true;
endif;
return $response;
endif;
}
$roles = [ 'customer', 'subscriber' ];
if ( check_current_user_role($roles) ) :
add_filter('show_admin_bar', '__return_false');
endif;
Don’t forget to replace ‘customer’ and ‘subscriber’ with user roles of your choice.
Click Save Changes. From now on, the admin bar will show up for everyone except the user roles you excluded. When someone logs into your site, the code checks their user role and either gives access or prevents them from seeing the admin bar based on your request.
4. Hiding the admin bar for all users except administrators
Arguably, administrators are the most active users on a WordPress website. Having quick access to important pages can be a blessing. In that case, you might want to enable the toolbar for administrators only.
Here’s how to hide WordPress admin bar for all users except the administrators:
a) Using a plugin
This is super easy. With the same Admin and Site Enhancements plugin. Again, go to Enhancements under the Tools menu. From the Admin Interface tab, enable Hide Admin Bar. Check all the user roles except for administrators.
b) Using code
You can hide the admin bar for all users except the administrator by adding code to your website. All you need to do is install the “Code Snippets” plugin, go to Snippets → Add New, and add the following code to the editor:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Click Save Changes. Every time someone logs into your WordPress site, the code checks the user role. If it’s not an administrator, the user is prevented from seeing the admin bar.
That’s it, folks! Now you know how to hide WordPress admin bar.
PRO TIP: If you are just looking to declutter the admin bar, then you can customize it. Just remove the parts that you don’t require and add parts that you do. We have a separate guide on that. Take a look – how to customize the WordPress toolbar.
Final thoughts on how to hide WordPress admin bar in 2024 🏁
The WordPress admin bar is a useful tool when working with your site every day, but sometimes it can display too much information, especially if the specific user seeing it cannot do much about it. Hence, removing it can be a good idea. You can always enable it back by simply removing the plugin or code snippet that helped you hide it in the first place.
Did you successfully hide the WordPress admin bar? Are you facing any challenges? Let us know in the comment section below.
Hi,
I’ve tried using your solution b of 4 to add code snippet into functions.php. But it doesn’t work. Could you please help?
By the way, I see in your screenshot that you have under Appearance two additional options “Theme Editor” and “Astra Options” which I don’t have. Which version of Astra do you use? I also use Astra Pro theme. Why?
BR
what if I just want to hide it while in mobile view?
Maybe you can try this plugin for doing that: https://wordpress.org/plugins/powerup/.
Or try this CSS code:
Access your theme’s functions.php file (Appearance > Theme Editor > functions.php).
Add the following code snippet:
@media screen and (max-width: 767px) {
#wpadminbar {
display: none !important;
}
}
Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!