The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Hide Admin Bar for Non-Admin Users

Shared by Amit Dholiya · November 23, 2026 · @show_admin_bar

4 views
1 upvote
Back to Snippets

Hides the black WordPress admin bar on the front end for every user except administrators. This is useful for membership sites, WooCommerce stores, and LMS sites where subscribers and customers shouldn’t see the toolbar.

How to add it

  1. Go to Appearance > Theme File Editor and open your child theme’s functions.php. Alternatively, install a snippets plugin like WPCode and click Code Snippets > Add Snippet > PHP Snippet.
  2. Paste the code below at the bottom of the file (or into the snippet box).
  3. Click Update File, or set the snippet to Active and click Save.
  4. Log in as a non-admin user (e.g., Subscriber) and check the front end. The admin bar should be gone.

How it works

  1. WordPress runs the show_admin_bar filter to decide whether the toolbar is displayed.
  2. The function checks whether the current user has the manage_options capability, which only administrators have by default.
  3. If they do, the bar stays visible. If not, the function returns false and the bar is hidden.
/**
 * Hide the admin bar for non-admin users.
 *
 * @param bool $show Whether to show the admin bar.
 * @return bool
 */
function my_hide_admin_bar_for_non_admins( $show ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return false;
    }
    return $show;
}
add_filter( 'show_admin_bar', 'my_hide_admin_bar_for_non_admins' );

Tested on

WordPress 6.8

Reported by the author on November 23, 2026. WPFolks has not verified this.

Not tested against WordPress 7.1.5. It may still work.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by