Clean up your frontend for logged-in users. Copy-paste code to disable the toolbar for everyone except administrators.
EN

Disable admin bar for all users except administrators (snippet)

5.00 /5 - (30 votes )
Last verified: March 1, 2026
Experience: 5+ years experience
Table of Contents

When building a membership site, online store (WooCommerce), or a platform where users log in, the default WordPress behavior can be annoying. Every logged-in user sees the black Admin Bar at the top of the screen.

While useful for you (the admin) to quickly edit posts or jump to the dashboard, it breaks the immersion for a regular customer. It looks “WordPress-y” and often overlaps with your custom header.

The problem: Admin bar clutter

The WordPress Admin Bar (also called the Toolbar) appears for all logged-in users by default. While it’s helpful for site administrators, it can be problematic for:

  • Membership Sites: Breaks the professional look
  • E-commerce Stores: Distracts from shopping experience
  • Customer Portals: Looks unprofessional
  • Custom Applications: Doesn’t match your design

Common Issues:

  • Overlaps with custom headers
  • Shows WordPress branding (looks unprofessional)
  • Reveals admin functionality to non-admins
  • Takes up vertical space
  • Can conflict with custom CSS

The complete solution

You don’t need a plugin to fix this. Just add this comprehensive snippet to your theme’s functions.php file or a site-specific plugin.

Basic implementation

/**
 * Disable Admin Bar for everyone except Administrators
 */
add_action('after_setup_theme', 'wppoland_remove_admin_bar');

function wppoland_remove_admin_bar() {
    if ( ! current_user_can( 'administrator' ) && ! is_admin() ) {
        show_admin_bar( false );
    }
}

How it works

  1. current_user_can('administrator'): Checks if the current user has the ‘Administrator’ role.
  2. ! is_admin(): Ensures we are on the frontend of the site (we don’t want to hide the bar inside the Dashboard!).
  3. show_admin_bar(false): The magic function that turns it off.

Important: The after_setup_theme hook runs early enough to prevent the admin bar from loading, which is more efficient than removing it after it’s rendered.

Advanced implementations

Role-Based hiding

Hide the admin bar for specific user roles:

/**
 * Hide admin bar for specific roles
 */
add_action('after_setup_theme', 'wppoland_remove_admin_bar_by_role');

function wppoland_remove_admin_bar_by_role() {
    if ( is_admin() ) {
        return; // Always show in admin area
    }

    $current_user = wp_get_current_user();

    // Hide for these roles
    $hidden_roles = array( 'subscriber', 'customer', 'contributor' );

    if ( array_intersect( $hidden_roles, $current_user->roles ) ) {
        show_admin_bar( false );
    }
}

Capability-Based hiding

Use capabilities instead of roles for more flexibility:

/**
 * Hide admin bar based on capabilities
 */
add_action('after_setup_theme', 'wppoland_remove_admin_bar_by_capability');

function wppoland_remove_admin_bar_by_capability() {
    if ( is_admin() ) {
        return;
    }

    // Hide if user can't edit posts
    if ( ! current_user_can( 'edit_posts' ) ) {
        show_admin_bar( false );
    }
}

Conditional hiding (page-Specific)

Hide admin bar on specific pages or post types:

/**
 * Hide admin bar on specific pages
 */
add_action('after_setup_theme', 'wppoland_conditional_admin_bar');

function wppoland_conditional_admin_bar() {
    if ( is_admin() ) {
        return;
    }

    // Hide on WooCommerce pages
    if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
        if ( ! current_user_can( 'manage_woocommerce' ) ) {
            show_admin_bar( false );
        }
    }

    // Hide on custom post types
    if ( is_singular( 'course' ) || is_singular( 'membership' ) ) {
        if ( ! current_user_can( 'administrator' ) ) {
            show_admin_bar( false );
        }
    }
}

User meta-Based control

Allow users to toggle admin bar via their profile:

/**
 * Allow users to toggle admin bar in profile
 */
add_action( 'show_admin_bar', 'wppoland_user_preference_admin_bar' );

function wppoland_user_preference_admin_bar( $show ) {
    if ( is_admin() ) {
        return $show;
    }

    $user_id = get_current_user_id();
    $user_preference = get_user_meta( $user_id, 'show_admin_bar_front', true );

    if ( $user_preference === 'false' ) {
        return false;
    }

    return $show;
}

/**
 * Add checkbox to user profile
 */
add_action( 'personal_options', 'wppoland_admin_bar_profile_option' );

function wppoland_admin_bar_profile_option( $user ) {
    ?>
    <tr>
        <th scope="row">Admin Bar</th>
        <td>
            <label>
                <input type="checkbox" name="show_admin_bar_front" value="1" <?php checked( get_user_meta( $user->ID, 'show_admin_bar_front', true ), '1' ); ?>>
                Show admin bar on frontend
            </label>
        </td>
    </tr>
    <?php
}

add_action( 'personal_options_update', 'wppoland_save_admin_bar_preference' );
add_action( 'edit_user_profile_update', 'wppoland_save_admin_bar_preference' );

function wppoland_save_admin_bar_preference( $user_id ) {
    if ( ! current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }

    $show_bar = isset( $_POST['show_admin_bar_front'] ) ? '1' : 'false';
    update_user_meta( $user_id, 'show_admin_bar_front', $show_bar );
}

You can hide the admin bar with CSS, but this is less efficient:

/* Hide admin bar with CSS */
#wpadminbar {
    display: none !important;
}

/* Adjust body padding */
.admin-bar .site-header {
    top: 0 !important;
}

Why not recommended:

  • Admin bar still loads (wastes resources)
  • JavaScript still executes
  • Can cause layout shifts
  • Not semantic (hiding vs. not loading)

Performance considerations

Why code beats CSS

CSS approach:

  • Admin bar HTML still loads (~15KB)
  • JavaScript still executes (~10KB)
  • Styles still load (~5KB)
  • Total: ~30KB wasted per page

Code approach:

  • Admin bar never loads
  • Zero overhead
  • Cleaner HTML
  • Better performance

Hook timing

Use after_setup_theme instead of init or wp_loaded:

// Good: Early hook, prevents loading
add_action('after_setup_theme', 'wppoland_remove_admin_bar');

// Bad: Too late, bar already loaded
add_action('wp_loaded', 'wppoland_remove_admin_bar');

Why use code instead of a plugin?

There are plugins like “Hide Admin Bar” that do exactly this. But why install a plugin (which adds database options and potential overhead) for 5 lines of code?

Plugin Overhead:

  • Database queries for options
  • Additional PHP files loaded
  • Plugin update maintenance
  • Potential conflicts
  • Extra HTTP requests

Code Benefits:

  • Zero overhead
  • Version controlled
  • No plugin conflicts
  • Faster execution
  • Part of your theme/plugin

When to Use a Plugin:

  • Non-technical users
  • Need GUI for configuration
  • Multiple sites with different settings
  • Client requests plugin-based solution

Real-World use cases

Use case 1: Membership site

/**
 * Hide admin bar for all members except admins
 */
add_action('after_setup_theme', function() {
    if ( is_admin() ) {
        return;
    }

    // Show only for administrators
    if ( ! current_user_can( 'administrator' ) ) {
        show_admin_bar( false );
    }
});

Use case 2: WooCommerce store

/**
 * Hide admin bar for customers, show for shop managers
 */
add_action('after_setup_theme', function() {
    if ( is_admin() ) {
        return;
    }

    $user = wp_get_current_user();

    // Hide for customers
    if ( in_array( 'customer', $user->roles ) ) {
        show_admin_bar( false );
    }

    // Show for shop managers and admins
    // (default behavior, no action needed)
});

Use case 3: Multi-Author blog

/**
 * Show admin bar for editors and admins, hide for authors/contributors
 */
add_action('after_setup_theme', function() {
    if ( is_admin() ) {
        return;
    }

    $hidden_roles = array( 'author', 'contributor', 'subscriber' );
    $current_user = wp_get_current_user();

    if ( array_intersect( $hidden_roles, $current_user->roles ) ) {
        show_admin_bar( false );
    }
});

Troubleshooting

Problem: Admin bar still shows

Possible causes:

  1. Hook timing issue
  2. User has show_admin_bar_front user meta set
  3. Another plugin/theme overriding

Solution:

// Force remove with higher priority
add_action('after_setup_theme', 'wppoland_force_remove_admin_bar', 999);

function wppoland_force_remove_admin_bar() {
    if ( ! current_user_can( 'administrator' ) && ! is_admin() ) {
        add_filter( 'show_admin_bar', '__return_false' );
        show_admin_bar( false );
    }
}

Problem: Admin bar hidden IN admin area

Solution: Always check is_admin():

function wppoland_remove_admin_bar() {
    if ( is_admin() ) {
        return; // Don't hide in admin area
    }

    if ( ! current_user_can( 'administrator' ) ) {
        show_admin_bar( false );
    }
}

Problem: Layout issues after hiding

Solution: Adjust body padding if needed:

/* Remove admin bar padding */
body.admin-bar {
    padding-top: 0 !important;
}

/* Or adjust header position */
.site-header {
    top: 0;
}

Best practices

1. Always check is_admin()

// Good
if ( ! is_admin() && ! current_user_can( 'administrator' ) ) {
    show_admin_bar( false );
}

// Bad (hides in admin area)
if ( ! current_user_can( 'administrator' ) ) {
    show_admin_bar( false );
}

2. Use capabilities, not roles

// Good: More flexible
if ( ! current_user_can( 'edit_posts' ) ) {
    show_admin_bar( false );
}

// Less flexible
if ( in_array( 'subscriber', $user->roles ) ) {
    show_admin_bar( false );
}

3. Document your logic

/**
 * Hide admin bar for non-administrators on frontend
 *
 * This improves UX for membership sites and e-commerce stores
 * by removing WordPress branding and admin functionality
 * from the customer-facing site.
 */
add_action('after_setup_theme', 'wppoland_remove_admin_bar');

4. Test all user roles

Always test with different user roles:

  • Administrator (should see bar)
  • Editor (decide based on needs)
  • Author (decide based on needs)
  • Subscriber (usually hide)
  • Customer (usually hide)

Summary

Hiding the WordPress Admin Bar for non-administrators is a simple but effective way to improve your site’s user experience. It makes your site look more professional and less “WordPress-y.”

Key Takeaways:

  • Use show_admin_bar( false ) in after_setup_theme hook
  • Always check is_admin() to avoid hiding in dashboard
  • Use capabilities for flexible control
  • Code solution is better than CSS or plugins
  • Test with different user roles

Benefits:

  • ✅ Cleaner frontend design
  • ✅ Better user experience
  • ✅ More professional appearance
  • ✅ No plugin overhead
  • ✅ Easy to implement

This simple tweak improves the User Experience (UX) of your site significantly, making it feel more like a professional application and less like a standard blog. In 2026, with the focus on user experience and performance, hiding the admin bar for non-admins is considered a best practice for membership sites, e-commerce stores, and custom applications.

Article FAQ

Frequently Asked Questions

Practical answers to apply the topic in real execution.

SEO-ready GEO-ready AEO-ready 5 Q&A
Will hiding the admin bar affect admin functionality?
No. Administrators will still see the admin bar. The code specifically checks for the 'manage_options' capability, which only administrators have. Other users won't see it on the frontend.
Can I hide the admin bar for specific user roles only?
Yes. Modify the condition to target specific roles: use current_user_can('subscriber') to hide only for subscribers, or use an array of roles to target multiple groups.
Where should I add this code?
Add to your child theme's functions.php file or use a site-specific plugin. Never add to the parent theme as it will be lost on theme updates.
Does this affect the backend admin dashboard?
No. This only affects the frontend of your site. The admin bar will still be visible in the WordPress dashboard for all users who have access.
Is there a plugin alternative to this code?
Yes, plugins like 'Hide Admin Bar Based on User Roles' exist, but the code snippet is more lightweight and doesn't add plugin overhead to your site.

Need an FAQ tailored to your industry and market? We can build one aligned with your business goals.

Let’s discuss

Related Articles