DEV Community

Aman Mehra
Aman Mehra

Posted on

How to Hide Admin Bar in WordPress?

There are many ways to hide the admin bar and many reasons you may want to hide the admin bar. You can do this by adding some code in your theme’s functions.php file.

Disable the WordPress Admin Bar for All Users

add_filter(‘show_admin_bar’, ‘__return_false’);
Enter fullscreen mode Exit fullscreen mode

Disable the WordPress Admin Bar for Specific User Roles

function hide_admin_bar( $show ) {
    if ( current_user_can( 'subscriber' ) || current_user_can( 'author' ) ) :
        return false;
    endif;

    return $show;
}
add_filter( 'show_admin_bar', 'hide_admin_bar' );
Enter fullscreen mode Exit fullscreen mode

Disable the WordPress Admin Bar for All Users Except Administrators

function hide_admin_bar( $show ) {

    if ( ! current_user_can( 'administrator' ) ) :
        return false;
    endif;

    return $show;

}
add_filter( 'show_admin_bar', 'hide_admin_bar' );
Enter fullscreen mode Exit fullscreen mode

You can hide admin bar on any condition based. More wordpress tutorial on www.yourblogcoach.com

Top comments (0)