WP Trick: Disabling the Admin Bar

Why remove the Admin Bar?

Recently, I solved an issue that had been bugging me for a little while: How to Remove the Admin Bar.

The reason why I wanted it gone is because I have subscribers who login to my site for certain resources and everything is accessible on the front end of the site. There was no reason to access to back end. It would just complicate things.

Easiest Solution

The easiest solution when you don’t want to do any coding is simply to un-check the Toolbar box in the Edit User screen.

Edit User - No Admin Toolbar | Andrew D. Forbes

You click ‘Update User’ at the bottom of the page and boom – it’s done and the user can’t see the Admin Bar. (I had been doing this method for a while.)

The problem with this method is you have to do it to ever single user and ideally as soon as the user is created (so they don’t start to wonder where that bar went).

This got me looking around for a better, more automatic way, so all new users would automatically have the Admin Bar disabled.

Coding Solution (just a little…)

Naturally, I stumbled upon another awesome WP Beginner article appropriately named “How to Disable WordPress Admin Bar for All Users Except Administrators“.

By simply adding the following few lines of codes to the theme’s functions.php file or a custom plugin, all my problems were solved!

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}

What this does is, unless the user has an ‘administrator’ level privileges, the Admin Bar will be disabled.

No more checking each user’s settings and un-checking their Toolbar option. It’s automatically disabled!

To add to this, I also figured out that if you have other users with a different user level that you wanted them to see the Admin Bar, such as Editor, you could enable this option by tweaking the code very slightly:

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin() && !current_user_can('editor')) {
         show_admin_bar(false);
    }
}

Now all users with Administrator and Editor level access will be able to see the Admin Bar, but everyone else cannot. This is great for any membership or subscription website with protected content and you want to keep users on the front end.

Hope this WordPress trick helps.