skip to Main Content

Search WordPress Code Snippets – Quick Solutions for Developers


How to Customize the Login Redirect Based on Role

Redirect users to different pages based on their roles after login.

add_action('wp_login', 'codebykp_role_based_login_redirect', 10, 2);
function codebykp_role_based_login_redirect($user_login, $user) {
    $role = $user->roles[0];
    switch ($role) {
        case 'administrator':
            wp_redirect(admin_url());
            break;
        case 'editor':
            wp_redirect(home_url('/editor-dashboard'));
            break;
        default:
            wp_redirect(home_url());
            break;
    }
    exit();
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Back To Top