Want to disable the WordPress admin bar for all users except administrators? You can use a simple function that checks user permissions using `current_user_can()`.
Here’s the snippet:
// Hide admin toolbar for non-admins function disable_admin_toolbar_except_admins() { if (!current_user_can('administrator') && !is_admin()) { show_admin_bar(false); } } add_action('after_setup_theme', 'disable_admin_toolbar_except_admins');
The function runs during the `after_setup_theme` action, which loads before most front-end rendering. It hides the admin bar for users who aren’t administrators and aren’t inside the WordPress dashboard.
This is ideal for keeping the UI clean for editors, authors, and subscribers. Just place the code inside your theme’s `functions.php` file or use a lightweight plugin.
Log in as a non-admin to confirm that the admin toolbar no longer appears on the front end.