DEV Community

Aman Mehra
Aman Mehra

Posted on

2 2

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs