How to hide the admin bar?

8 May 2023

In this tutorial you will learn now to hide the admin bar when logged in. This can be useful if you have a membership site and you don’t want to give users the ability to log out.

To hide admin bar for all users

/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );

To hide the admin bar for certain user levels.
Remember to change the user levels at the bottom of the code. This particular code hides the admin bar for the ‘customer‘ role and the ‘subscriber‘ role.

function tf_check_user_role( $roles ) {
    /*@ Check user logged-in */
    if ( is_user_logged_in() ) :
        /*@ Get current logged-in user data */
        $user = wp_get_current_user();
        /*@ Fetch only roles */
        $currentUserRoles = $user->roles;
        /*@ Intersect both array to check any matching value */
        $isMatching = array_intersect( $currentUserRoles, $roles);
        $response = false;
        /*@ If any role matched then return true */
        if ( !empty($isMatching) ) :
            $response = true;        
        return $response;
$roles = [ 'customer', 'subscriber' ];
if ( tf_check_user_role($roles) ) :
    add_filter('show_admin_bar', '__return_false');

If logging out is essential, you can use the\wp-admin address to get back to the dashboard.

To see what your customer sees, you can utilise a User Role Switching Plugin such as

Was this article helpful?



Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy