Skip to content

Disable the Admin Bar for Specific Roles

Hides the front-end admin toolbar for non-staff roles like Subscriber or Customer, while keeping it visible for roles that actually use its quick links.

Difficulty
Beginner
Reading time
~1 min
Where to add it
Your child theme's functions.php
Last updated

The Problem

By default, any logged-in WordPress user sees the black admin toolbar across the entire front end of the site, including customers and subscribers who have no use for its "Edit Post," "New," or site-health quick links. On a customer-facing site that's a visual inconsistency at best — a toolbar that looks like an internal tool showing up for people outside the team — and on some themes it can visibly shift layout or overlap fixed headers, since WordPress reserves space for it by default wherever it's shown.

The Code

php
add_filter( 'show_admin_bar', 'devmubs_hide_admin_bar_for_role' );

function devmubs_hide_admin_bar_for_role( $show ) {
    if ( current_user_can( 'edit_posts' ) ) {
        return $show;
    }

    return false;
}

How It Works

The `show_admin_bar` filter runs on every front-end page load right before WordPress decides whether to render the toolbar, and receives whatever value core has already determined (`true` for any logged-in user by default). The callback checks `current_user_can( 'edit_posts' )` as a stand-in for "has genuine admin-area business" — Authors, Editors, and Administrators pass and keep the bar exactly as WordPress would have shown it; Subscribers and WooCommerce Customers don't pass, since they lack that capability by default, and the filter returns `false` for them instead, which suppresses the toolbar entirely for that request.

Where To Add This

Your child theme's functions.php. This is a single small filter with no dependency on anything else, so keeping it in the theme's functions.php alongside other simple front-end display tweaks is reasonable — there's little value in isolating one filter this size into its own plugin.

Warnings & Caveats

  • If another plugin grants `edit_posts` to a role that isn't actually staff (some community or forum plugins do this for contributor-style roles), that role will keep seeing the admin bar too — check the capability against your actual role setup rather than assuming the defaults apply.
  • Always back up your site before adding custom code.

We use cookies

We use essential cookies to run this site, and optional cookies to understand usage and remember your preferences. Read our Cookie Policy to learn more.