Skip to main content
Login Join
Snippet · PHP

Disable the WordPress Admin Bar for All Users Except Administrators

Shared by Amit Dholiya · July 26, 2026 · @after_setup_theme

1 view
Back to Snippets

Description

The WordPress Admin Bar is displayed for logged-in users on the frontend by default. This snippet hides the Admin Bar for all users except administrators, providing a cleaner browsing experience while allowing administrators to retain quick access to site management tools.

Steps

  1. Open your active theme’s functions.php file or a custom functionality plugin.
  2. Add the code below.
  3. Save the file.
  4. Log in as a non-administrator to verify the Admin Bar is hidden on the frontend.
/**
 * Hide the Admin Bar for non-administrators.
 */
function wpfolks_hide_admin_bar_for_users() {

    if ( ! current_user_can( 'administrator' ) && ! is_admin() ) {
        show_admin_bar( false );
    }
}
add_action( 'after_setup_theme', 'wpfolks_hide_admin_bar_for_users' );
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