WordPress: Redirect Users After Login Based on Role

By default, WordPress redirects everyone to the admin dashboard after login. On membership sites or sites with custom front-end interfaces, you often want subscribers to land on their profile page, editors on the post list, and administrators on the dashboard. The login_redirect filter makes this straightforward.

Problem: After logging in, all WordPress users land on the same URL — typically the admin dashboard — regardless of their role, which is confusing for subscribers or customers who should be sent to the front end.

Solution: Hook into login_redirect and check $user->roles to return a different URL per role. Administrators and editors go to the dashboard; subscribers, customers, and other front-end roles go to the home page or a dedicated account page.

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

function redirect_after_login( $redirect_to, $requested_redirect_to, $user ) {
    // $user might be a WP_Error on failed login — check first
    if ( is_wp_error( $user ) ) {
        return $redirect_to;
    }

    // Administrators and editors: go to the admin dashboard
    if ( in_array( 'administrator', $user->roles, true )
      || in_array( 'editor', $user->roles, true ) ) {
        return admin_url();
    }

    // Authors: go to their post list
    if ( in_array( 'author', $user->roles, true ) ) {
        return admin_url( 'edit.php' );
    }

    // Subscribers and everyone else: go to the account page on the front end
    if ( ! empty( $requested_redirect_to ) ) {
        return $requested_redirect_to; // respect the ?redirect_to= parameter
    }

    return home_url( '/my-account/' );
}

Redirect users away from the admin dashboard if they try to access it directly (useful for subscriber-only sites):

add_action( 'admin_init', 'restrict_admin_access' );

function restrict_admin_access() {
    $user = wp_get_current_user();

    // Allow AJAX requests from all roles (needed by front-end plugins)
    if ( wp_doing_ajax() ) return;

    // Only block subscribers
    if ( in_array( 'subscriber', $user->roles, true ) ) {
        wp_redirect( home_url( '/my-account/' ) );
        exit;
    }
}

NOTE: The login_redirect filter receives the URL that WordPress would redirect to by default as the first argument and the URL from the redirect_to query parameter as the second. Always check the redirect_to parameter before overriding it — a user who was redirected to the login page from a specific admin URL should still land on that URL after authenticating.