Buy All 47 Premium Themes For the Price Of $129.99

How to Create a Custom WordPress Login Redirect Based on User Role

By default, WordPress sends all users to the same dashboard after login.
However, in real projects you often need different redirects depending on user roles such as admin, editor, customer, or subscriber.

In this article, you will learn how to create a dynamic login redirect system using WordPress hooks.

Why Role-Based Redirects Are Useful

Different users have different needs after logging in.

  • Admins should go to the dashboard
  • Customers should go to the shop or account page
  • Subscribers should go to a welcome page

The WordPress Hook We Will Use

We will use:

login_redirect

This filter allows us to modify where users are redirected after login.

Example Code


add_filter('login_redirect', 'role_based_login_redirect', 10, 3);

function role_based_login_redirect($redirect_to, $request, $user) {

    if (isset($user->roles) && is_array($user->roles)) {

        if (in_array('administrator', $user->roles)) {
            return admin_url();
        }

        if (in_array('editor', $user->roles)) {
            return admin_url('edit.php');
        }

        if (in_array('customer', $user->roles)) {
            return site_url('/my-account');
        }

        if (in_array('subscriber', $user->roles)) {
            return site_url('/welcome');
        }
    }

    return $redirect_to;
}

How It Works

  • Checks the logged-in user role
  • Applies a custom redirect based on role
  • Falls back to default redirect if no rule matches

Customization Ideas

  • Redirect users based on membership level
  • Send first-time users to onboarding page
  • Redirect based on last visited page
  • Send users to seasonal landing pages