354

How to Hide Admin Bar for All Users Except Admins in WordPress

Powered by WPCodeBox

Learn how to easily hide the WordPress admin bar for all users except administrators. This guide helps you manage user access and optimize your WordPress site.


<?php

add_filter('show_admin_bar',function( $show_admin_bar ) {
    if(!current_user_can('manage_options')) {
        return false;
    }
    return $show_admin_bar;
});

Quick Steps to Hide Admin Bar for All Users Except Admins

Follow these simple steps to hide the admin bar for all users except administrators:

  1. Install and activate the WPCodeBox plugin, then navigate to WPCodeBox 2 in your WordPress dashboard.
  2. Copy the code snippet above and paste it into the WPCodeBox code editor.
  3. Give your snippet a descriptive title (like “Hide Admin Bar for Non-Admins”), select PHP as the type, then click Save.
  4. Enable the snippet by toggling the switch to the active position.
  5. Test the changes by logging in with different user roles to verify the admin bar only appears for administrators.

That’s it! The admin bar is now hidden for all non-administrator users on your WordPress site.

Hide Admin Bar for All Users Except Admins – Additional Information

WordPress User Roles and Admin Bar Access

WordPress has a built-in user role system that determines what different users can and cannot do on your site. The administrator role has the highest level of permissions, including full control over themes, plugins, users, and settings. Other roles, like editors, authors, contributors, and subscribers, have progressively fewer capabilities.

The WordPress admin bar appears automatically for users with sufficient permissions, providing quick access to backend functions. By default, administrators, editors, authors, and contributors see the admin bar on both the frontend and backend, while subscribers typically only see it in the admin area.

Why Hide the Admin Bar for Non-Admins

Hiding the admin bar for non-administrator users makes sense for several reasons. For client websites, the admin bar often confuses visitors and can interfere with your site’s design and navigation. It adds visual clutter that serves little purpose for users who don’t need backend access.

On membership sites and multi-author blogs, hiding the admin bar creates a cleaner user experience for regular members while maintaining quick access for content managers. This approach reduces cognitive load and prevents users from accidentally accessing areas they shouldn’t explore.

We also have a video in which we use this snippet:

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.