Admin UX PHP Beginner

Remove the Admin Bar for Non-Admin Users

Last updated: May 6, 2026

WordPress displays the admin toolbar at the top of every page for any logged-in user by default. For administrators and editors who need to jump into the admin or quickly edit a post, this makes sense. For subscribers, WooCommerce customers, members, or any other front-end-only user role, the toolbar is irrelevant, it clutters the page layout, can push fixed headers down unexpectedly, and exposes links to the admin area that those users don’t need to see.

This snippet removes the admin toolbar on the front end for any user who doesn’t have the manage_options capability, which is held only by administrators by default. Everyone else gets a clean, uninterrupted front-end experience.

The Code

Add this to your functions.php or a site-specific plugin. It hooks into after_setup_theme and calls show_admin_bar( false ) for non-administrators.

Why after_setup_theme

The after_setup_theme hook runs early enough in the WordPress load process for show_admin_bar() to take effect before the toolbar is rendered. Using a later hook like wp_head or init can still work but may result in the toolbar being briefly rendered and then hidden via CSS, depending on the theme. Using after_setup_theme prevents the toolbar from being built at all for the affected users.

The is_admin() guard at the top ensures the function exits immediately on admin pages, where the toolbar should always be visible regardless of role.

Customising by Role or Capability

The manage_options capability is a reliable proxy for administrator role but can be replaced with any capability. If you want editors to also see the toolbar, check for edit_posts instead, both administrators and editors hold that capability. If you’re using a membership plugin with custom roles, check for a capability specific to that role.

You can also use WordPress’s built-in wp_roles() or current_user_can() with any registered capability string. The approach is the same, replace the capability check in the snippet with whichever capability marks users who should see the toolbar.

Per-User Control

WordPress also gives individual users control over their own toolbar visibility through their profile settings under Users → Profile → “Show Toolbar when viewing site”. The programmatic show_admin_bar( false ) call overrides this setting, users in the affected roles will never see the toolbar regardless of what their profile says. If you want to respect individual preferences while still hiding it from low-privilege roles, add an additional check: get_user_meta( get_current_user_id(), 'show_admin_bar_front', true ) === 'true'.

CSS Impact

When the admin toolbar is visible, WordPress adds a admin-bar class to the <body> element and injects a small stylesheet that adds 32px of top margin or padding to account for the toolbar height. Removing the toolbar via this snippet also prevents those styles from being injected, so your layout is unaffected for non-admin users.

functions.php
add_action( 'after_setup_theme', function() {
    if ( is_admin() ) return;

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

Built by Nahnu Plugins

Need something more powerful than a snippet?

Our commercial plugins go further, built for serious WordPress sites with full support, updates, and documentation included.

Browse All Plugins →

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only