Category Archives: BuddyPress

Only show the WordPress toolbar to Admins

If you wish to disable the WordPress toolbar for all users except Admins, then place this small snippet of code in your theme’s function file.

// Remove Toolbar for users except for Admins
if (!current_user_can('administrator')) :
  show_admin_bar(false);
endif;

Why would you want to disable the toolbar in the first place? Well for one, if you run a BuddyPress site and most members on your website are BBPress forum participants, then the toolbar is overkill as you already have your user profile on the front-end of the website. In fact any kind of members plugin that has user profiles on the front-end of the site are better without the toolbar.

However, retaining the toolbar for Admins is a good idea if you decide to disable the toolbar for other roles. The reason is it gives quicker access to the Admin area without having to append /wp-admin/ to the URL to enter the CMS. It is also handy as you can directly edit pages when on the website as the ‘Edit’ link on the toolbar is available. Otherwise you have to enter the CMS and go to Pages, then search for the page. More often than not, you notice that pages need a correction or edit when you are reading the page from the website, so you want to be able to fix it easily right there and then.

If you want other user roles to have access to the toolbar like Editors, then try the code below and edit depending on what user roles you want to show the toolbar too.

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' ) ) {
        show_admin_bar(false);
    }
}

There are of course a number of plugins that can do this for you, but I prefer to add code to the function.php file in your theme as it is much lighter than loading a plugin. Often plugins have a number of features that you may not use, but you have to load that code anyway.