Disable WordPress dashboard for subscribers

Learn how to disable the WordPress dashboard for subscribers to your WordPress website in this tutorial.

Disable WordPress dashboard for subscribers

There's sometimes scenarios where you want to disable the WordPress dashboard for certain users such as subscribers. You may also want to disable the admin bar for subscribers too.

This isn't an uncommon scenario, this post tells you how to both disable the WordPress Dashboard for subscribers and disable the admin bar.

Adding the action

If you're developing a WordPress theme, you are more than likely familiar with WordPress' actions and hook mechanism.

We're essentially going to add a new action to the admin init in order to achieve our objective of disabling the WordPress dashboard for subscribers. Add this to your functions.php file:

add_action('admin_init', 'disable_dashboard');
function disable_dashboard() {
    if (current_user_can('subscriber') && is_admin()) {
        wp_redirect(home_url()));
        exit;
    }
}

The above code will redirect subscribers to the home page. You could redirect to any page on your site here.

Disable WordPress dashboard for all but administrators

You may want to disable the dashboard for anyone who isn't an administrator. You can achieve this with:

add_action('admin_init', 'disable_dashboard');
function disable_dashboard() {
    if (!is_user_logged_in()) {
        return null;
    }
    if (!current_user_can('administrator') && is_admin()) {
        wp_redirect(home_url()));
        exit;
    }
}

Notice this time I'm returning null for when users are not logged in. This is to ensure that admin-ajax.php still works for logged out users, otherwise it tries to redirect.

That's pretty much it. Very straight forward. You could also target specific capabilities instead of for user roles, a full list can be found on the WordPress codex.

Hiding the admin bar for subscribers

Aside from disabling the dashboard, you might want to also hide the admin bar for subscribers too. Simply add the following action to your functions.php file:

add_action('admin_init', 'disable_admin_bar');
function disable_admin_bar() {
    if (current_user_can('subscriber')) {
        show_admin_bar(false);
    }
}

As with before, it is possible to switch 'subscriber' for any user type or capability. As with before, the WordPress Codex has a full list of capabilities to target.

That's essentially it. If you have any questions or feedback, feel free to leave a comment below.