How to Hide WordPress Admin Bar: Ultimate Guide

How to Hide WordPress Admin Bar: Ultimate Guide

Wondering how to hide the WordPress admin bar?

The admin bar (also called the toolbar) appears on the top of a page of a WordPress website. You have to be logged in to see it. It offers quick access to pages like Dashboard, Themes, Widgets, Menus, Customize, New Page, Edit Post, etc.

Although, by default, all WordPress users can view the admin bar, rarely do subscribers need it to access the backend. And for developers, it can really throw off the design of the front page. In such cases, hiding the admin bar is necessary. So, in this article we will show you how to disable the WordPress admin bar for:

  • All users
  • All users excluding the admin
  • Specific users
  • Specific user roles

Let’s dive right in.

How to hide WordPress admin bar

There are two ways to hide the WordPress admin bar. The easy way is to install a plugin and the hard way is to insert a code snippet manually. 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:

Using a plugin

Install and activate the “Hide Admin Bar on User Roles” plugin. Then go to Settings → Hide Admin Bar Settings. Select Hide Admin Bar for All Users and hit Save.

Hide admin bar for all users with a plugin

Side Note: If you can’t get the “Hide Admin Bar on User Roles” plugin to work on your WordPress website, try Custom Dashboard & Login Page or Hide Admin Bar. Both plugins are super easy to use.

Using code

Installing and managing new plugins can be a headache. So, if you are not a fan of adding new plugins to your WordPress website, we recommend going the manual way, i.e. adding a code snippet to disable the WordPress admin bar. Below are the steps you need to take:

Go to Appearance → Theme Editor → function.php. Scroll down to the end of the page 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:

how to hide admin bar for all users - manual methodManually hiding the admin bar for all users

You can also disable the admin bar by using CSS. Just go to Appearance → Customize → Additional CSS and add the following CSS code:

#wpadminbar { display:none !important;}
inserting CSS in wordpress themeInserting CSS in WordPress theme

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.

hide toolbar from dashboardHiding the toolbar from the WordPress dashboard

The manual method works for a handful of users but for a large number of users, you might want to disable it based on user roles.

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:

Using a plugin

Install the “Hide Admin Bar Based on the User Roles” plugin and go to Settings → Hide Admin Bar Settings → User Roles. Select the user roles you want to prevent from accessing the WordPress dashboard and save your settings.

how to hide admin bar for user roles with a pluginHiding the admin bar for specific user roles with a plugin

Using code

If using a plugin is not your cup of tea, then insert the following code in your theme’s function.php file:

function tf_check_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 ( tf_check_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.

how to hide admin bar for specific user roles - manual methodManually hiding the admin bar for specific user roles

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:

Using a plugin

This is super easy. Activate the “Hide Admin Bar on the User Roles” plugin on your website. Then go to Settings → Hide Admin Bar Settings → Hide Admin Bar for Selected User Roles. Now, choose all the user roles except for Administrator. Save your settings.

how to hide admin bar for all users except administratorHiding the admin bar for all users except administrators with a plugin

Using code

You can hide the admin bar for all users except the administrator without using a plugin. All you need to do is add the following code snippet 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);
  }
}
manually hiding admin bar from all users except administratorsManually hiding admin bar from all users except administrators

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

The WordPress admin bar is a useful tool but sometimes it hinders more than it helps. 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.

If you do need to enable it, just remember to take a backup of your site before introducing any modifications.

Did you successfully hide the WordPress admin bar? Are you facing any challenges? Let us know in the comment section below.

Free guide

5 Essential Tips to Speed Up
Your WordPress Site

Reduce your loading time by even 50-80%
just by following simple tips.

Keep reading the article at ThemeIsle Blog. The article was originally written by Sufia Banu on 2021-11-04 05:50:00.

The article was hand-picked and curated for you by the Editorial Team of WP Archives.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

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

Show Your ❤️ Love! Like Us
Scroll to Top