Skip to main content
Login Join
Snippet · PHP

Role-Based Login Redirect for WordPress Users

Shared by Dhaval Vachhani · May 22, 2026 · @login_redirect

17 views
Back to Snippets

Redirect users to different pages after login based on their WordPress role.

This snippet sends administrators to the WordPress dashboard while redirecting all other users to a custom account page. Useful for membership sites, WooCommerce stores, client portals, and custom user experiences.

Features

Best for

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

    // Check if user logged in successfully
    if (isset($user->roles) && is_array($user->roles)) {

        // Redirect based on role
        if (in_array('administrator', $user->roles)) {
            return admin_url();
        } else {
            return home_url('/my-account/');
        }
    }

    return $redirect_to;
}

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