Hide the Admin Bar in WordPress

Once we start membership integration, adding non-admin users, the admin toolbar seating on top of the page for logged in users becomes annoying. The toolbar for regular user such as subscriber provides only links to edit profile or link to log out. A fully customized membership website should has other options to provide these links. In almost all my projects, clients want to hide it from regular users.

Here is a snippet which will stop toolbar from showing:

add_filter('show_admin_bar', '__return_false');

This is simple yet powerful. It will leave the Admin toolbar available in Dashboard but hide it on all front-end pages for all users including admin users.

If we still want to show this to administrators, then use following code:

if (! current_user_can('administrator')) {
    show_admin_bar(false);
}

or using following code to show admin bar for all users who has the capability of “manage_options”

if (! current_user_can('manage_options')) {
    show_admin_bar(false);
}