Redirect Users After Login Based on User Role

Problem/Use Case:

You may want admins to land in the dashboard while subscribers go to a custom page after login.

Snippet:

// Redirect users after login
function my_login_redirect($redirect_to, $request, $user) {
    if (isset($user->roles) && is_array($user->roles)) {
        if (in_array('administrator', $user->roles)) {
            return admin_url();
        } else {
            return home_url('/welcome/');
        }
    }
    return $redirect_to;
}
add_filter('login_redirect', 'my_login_redirect', 10, 3);

Explanation:
This redirects the login logo link to your site’s homepage.

Where to Place It:
In functions.php. or a custom snippet plugin

Bonus Tip:
Pair this with a custom logo for a fully branded login page.

Ndifon Luke
Ndifon Luke

Ndifon Luke is the founder & owner of Uncle Luke Digitals—a web design, digital marketing freelancer based in Bamenda, Cameroon. He has over 6 years of expertise in digital marketing and is very passionate about working with clients in achieving their business objectives.