If you want to disable the WordPress toolbar for all users except administrators, put this small piece of code in your template function file.

// Remove Toolbar for users except for Admins
if (!current_user_can('administrator')) :

Why do you want to disable the toolbar in the first place? Well, if you run a BuddyPress site and most of your website members are members of the BBPress community, then the toolbar is too much because you have your user profile at the bottom of the website. In fact, any plugin with a user profile, it is better to use the front of the site without a toolbar.

If you decide to disable the toolbar for other roles, keeping the toolbar for Admins is a good idea. This is due to faster access to the admin area without the need to attach / wp-admin / to the URL to enter the CMS. Also, since the “Edit” link is available in the toolbar, you can edit pages directly while editing on the web. Otherwise you have to enter the CMS and go to Pages, then search the page. Most of the time, you find that when you read a page from a website, the pages need to be modified or edited, so you want to easily fix it here and there.

If you want other user roles, such as editors, to access the toolbar, try the following code and edit the toolbar, depending on how you want the user roles to be displayed.

add_action( 'after_setup_theme', 'remove_admin_bar' );
function remove_admin_bar() {
if( ! current_user_can( 'administrator' ) || ! current_user_can( 'editor' ) || ! current_user_can( 'author' ) ) {

Of course, there are a number of plugins that can do this for you, but I prefer to add code to the function.php file in my theme, as it is much lighter than loading a plugin. Plugins often have a number of features that you may not use, but you will have to download that code anyway.