How to Hide the Front-End Admin Bar for Specific Users in WordPress
In WordPress, logged-in users see a black admin bar at the top of the front-end website by default. For security, aesthetics, or to simplify the interface, you may want to hide this toolbar for specific user roles (e.g., non-administrators).
Method 1: Using a Code Snippet (Recommended)
Add the following code to the end of your current theme's functions.php file, or use a code snippet plugin like Code Snippets.
// Hide front-end admin bar for users without 'manage_options' capability
add_filter('show_admin_bar', function($show) {
if (!current_user_can('manage_options')) {
return false;
}
return $show;
});
Code Explanation:
current_user_can('manage_options')checks if the logged-in user has the 'manage_options' capability, typically granted to Administrator roles.- If the user lacks this capability, the
add_filterhook returnsfalseforshow_admin_bar, hiding the toolbar. - This method only affects the front-end; the WordPress admin dashboard remains unchanged.
Method 2: Via User Profile Settings
Users can hide the toolbar individually by going to Dashboard → Users → Your Profile and unchecking the "Show Toolbar when viewing site" option. This requires manual configuration per user and is not suitable for bulk control.
Method 3: Using a Plugin
If you prefer not to edit code, consider these plugins for more granular control:
- Admin Bar Disabler: A lightweight plugin to disable the front-end admin bar for all users with one click.
- Hide Admin Bar Based on User Roles: Allows selective hiding of the toolbar based on user roles.
Important Notes
- Always back up your site before editing theme files like
functions.php. - Using a code snippet plugin is safer and more manageable, preventing code loss during theme updates.
- Hiding the admin bar removes quick front-end links like "Edit Post" and "New". Consider your users' needs before implementing.