How to Hide the Admin Bar for Subscribers in WordPress

October 28, 2025
How to Hide the Admin Bar for Subscribers in WordPress

How to Hide the Admin Bar for Subscribers in WordPress

The WordPress admin bar (the black toolbar at the top of the site) appears for all logged-in users by default. While it’s useful for administrators and editors, it can clutter the view for regular users or members. In this guide, you’ll learn how to hide the admin bar for subscribers (or any role) using simple code — no plugins needed.

Why Hide the Admin Bar?

  • Cleaner user experience: Visitors who log in (for memberships or comments) see your site as intended.
  • Security: Hides quick links to the admin area for low-level users.
  • Design consistency: Ensures the front-end layout isn’t affected by the admin toolbar height.

Method 1: Hide Admin Bar for Subscribers with Code

Add the following code to your functions.php file (inside your theme or child theme):

<?php
// Hide admin bar for subscribers
add_action( 'after_setup_theme', function () {
    if ( current_user_can( 'subscriber' ) ) {
        show_admin_bar( false );
    }
} );

This checks if the logged-in user has the subscriber role and disables the toolbar for them on the front end.

How It Works

  • after_setup_theme runs early enough to modify the admin bar display.
  • current_user_can('subscriber') ensures only users with that role are affected.
  • show_admin_bar(false) hides the toolbar entirely on the front-end pages.

Method 2: Target Multiple Roles

If you want to hide the admin bar for several roles (e.g., subscriber and contributor), extend the logic like this:

<?php
add_action( 'after_setup_theme', function () {
    $user = wp_get_current_user();
    $roles_to_hide = [ 'subscriber', 'contributor' ];

    if ( array_intersect( $roles_to_hide, (array) $user->roles ) ) {
        show_admin_bar( false );
    }
} );

Method 3: Remove “Show Toolbar” Option for Subscribers

You can prevent subscribers from toggling the toolbar in their profile settings:

<?php
// Force-disable the "Show Toolbar" option in user profiles
add_filter( 'show_admin_bar', function ( $show ) {
    return current_user_can( 'subscriber' ) ? false : $show;
} );

This hides the bar and disables the setting in Users → Profile for subscribers.

Optional: Hide the Admin Dashboard Access

To completely block subscribers from accessing /wp-admin, add this redirect:

<?php
add_action( 'admin_init', function () {
    if ( current_user_can( 'subscriber' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
        wp_redirect( home_url() );
        exit;
    }
} );

This ensures that if a subscriber tries to visit the admin panel, they’ll be redirected to your homepage instead.

Optional CSS Fix: Prevent Layout Shift

When hiding the admin bar, WordPress no longer adds the admin-bar class to the HTML tag, so you usually don’t need to adjust CSS. But if your layout was built assuming that padding existed, you can reset it:

html {
  margin-top: 0 !important;
}

Testing the Change

  1. Log in as a subscriber (create a test user if needed).
  2. Visit the front end of your site — the black admin toolbar should no longer appear.
  3. Log in as an administrator or editor to confirm the toolbar still works for them.

Conclusion

Hiding the admin bar for subscribers keeps your WordPress site clean and professional for front-end users. The simplest approach is to use show_admin_bar(false) for the roles you want to exclude. Combine it with admin redirects if you’re running a membership or user-login site for extra polish and security.

Tip: Always use a child theme for modifications to avoid losing them after theme updates.

Avatar

Written by

satoshi

I’ve been building and customizing WordPress themes for over 10 years. In my free time, you’ll probably find me enjoying a good football match.