How to Hide the WordPress Toolbar for Logged-In Users
How to Hide the WordPress Toolbar for Logged-In Users
How to Hide the WordPress Toolbar for Logged-In Users
The WordPress admin toolbar appears at the top of the screen for logged-in users, providing quick access to the dashboard and other tools. However, in some cases, you may want to hide the toolbar for certain users, such as subscribers or non-administrators, to create a cleaner frontend experience.
In this guide, we’ll walk through different methods to hide the WordPress toolbar for logged-in users.
Why Hide the WordPress Toolbar?
Hiding the WordPress toolbar can be useful when:
- Running a membership site where subscribers don’t need backend access.
- Keeping a clean frontend view for logged-in users.
- Restricting access to the WordPress admin bar for security or aesthetic reasons.
Method 1: Hiding the Toolbar for All Users Except Administrators
The following snippet will hide the admin toolbar for all users except administrators. Add this code to your theme’s functions.php file or use the Code Snippets plugin:
Explanation
current_user_can('manage_options')
: Checks if the user has admin privileges.show_admin_bar(false)
: Disables the toolbar.add_action('after_setup_theme', 'hide_admin_bar_except_admins')
: Ensures the function runs when WordPress initializes.
Method 2: Hiding the Toolbar for Specific User Roles
Explanation
is_user_logged_in()
: Checks if a user is logged in.current_user_can('subscriber')
: Targets only subscribers.show_admin_bar(false)
: Hides the admin bar.
Method 3: Using CSS to Hide the Toolbar
If you prefer a CSS-based solution, add the following code to your theme’s Additional CSS section or your custom stylesheet:
Note:
This method only hides the toolbar visually but does not remove its functionality. Users can still access admin pages directly.
Method 4: Hiding the Toolbar via a Plugin
If you prefer a plugin-based solution, you can use a free plugin like Hide Admin Bar or Admin Bar Disabler available in the WordPress repository. These plugins allow you to toggle the toolbar visibility for different user roles without writing code.
Wrap Up
Hiding the WordPress toolbar can help create a cleaner and more user-friendly experience for logged-in users who don’t need backend access. Whether you use a code snippet, CSS, or a plugin, you can easily control who sees the admin toolbar.