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
- 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. - Paste the code below at the bottom of the file (or into the snippet box).
- Click Update File, or set the snippet to Active and click Save.
- Log in as a non-admin user (e.g., Subscriber) and check the front end. The admin bar should be gone.
How it works
- WordPress runs the
show_admin_barfilter to decide whether the toolbar is displayed. - The function checks whether the current user has the
manage_optionscapability, which only administrators have by default. - If they do, the bar stays visible. If not, the function returns
falseand 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.
