How to redirect if user has specific role in wordpress

0 Comments

Last updated on

I created one simple function when you require a redirect of a specific role (Administrator, Subscriber, Contributor, Author, Editor) in WordPress

Use this snippet in your theme’s functions.php. It will redirect any users with the user role of ‘subscriber’ to your chosen URL.

function redirect_users_role() {

    $current_user   = wp_get_current_user();
    $role_name      = $current_user->roles[0];

    if ( 'subscriber' == $role_name ) {
        wp_redirect( get_home_url() . '/redirect_page' );
        exit;
    }

}
add_action( 'admin_init', 'redirect_users_role' );

Leave a Comment