Disable WP Admin Toolbar for Non-Admins

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.