In this post, I’ll just share a code snippet that will allow you to hide the WordPress admin elements to users who have signed up your site under the Subscriber roll.

The Problem

You’ve found a cool plugin that allows people to signup on your WordPress site and have access to something that the plugin provides on the frontend of your site, but now that a user is logged in there are two problems:

  1. They see the WordPress admin bar at the top of your website.
  2. They can go to — Not that they can do any harm with a low-level user account, but still maybe seems unprofessional in some cases.

An example? — I’ve personally come across this recently in building sites where I used bbPress to make a support website and Easy Digital Downloads to make a little online store. In both of these websites, I didn’t want users doing anything in the WordPress admin panel because both of these plugins provide ways to give the users everything they need on the frontend of the site when logged in.

The Solution

These two functions should help you solve that little dilemma. Below I’ve picked a capability of “edit_posts” which is just outside of the roles of a Subscriber user (see roles vs capabilities table). I picked the “edit_posts” capability as the example here because this is about as low as a user can be on the capabilities table.

And so we’re basically saying the following:

  1. If the user is logged in, but can’t edit posts, then hide the admin bar on the frontend of the website.
  2. If the user is logged in, but can’t edit posts, do not allow them to access the WordPress admin panel.

This code could go in functions.php of your theme or in a plugin you create.

 * Disable admin bar on the frontend of your website
 * for subscribers.
function themeblvd_disable_admin_bar() { 
	if ( ! current_user_can('edit_posts') ) {
		add_filter('show_admin_bar', '__return_false');	
add_action( 'after_setup_theme', 'themeblvd_disable_admin_bar' );

 * Redirect back to homepage and not allow access to 
 * WP admin for Subscribers.
function themeblvd_redirect_admin(){
	if ( ! defined('DOING_AJAX') && ! current_user_can('edit_posts') ) {
		wp_redirect( site_url() );
add_action( 'admin_init', 'themeblvd_redirect_admin' );