Redirect users after login based on their role

WordPress sends every user to the same page after login — usually the dashboard. That works fine for administrators who manage content and settings daily, but editors, subscribers, and custom-role users rarely need /wp-admin at all. Sending a subscriber to the backend after login creates confusion and exposes UI elements they can’t use. It also makes your site feel unpolished and unprofessional to non-technical users. On membership sites and online stores this becomes even more noticeable: a customer who just logged in expects to see their account page or order history, not a WordPress admin panel. The good news is that WordPress provides a dedicated filter hook, login_redirect, that fires on every successful login and lets you return any URL based on the authenticated user’s role. The hook receives three arguments: the default redirect URL, the originally requested URL, and a WP_User object that carries the role information you need to make the decision. You can check for as many roles as your site has and send each one to a completely different destination. Administrators can go straight to wp-admin/, editors to the posts list, and subscribers to their profile or a custom front-end dashboard. No extra plugins required — a few lines in functions.php are all it takes.

Problem: All users land on the same page after login regardless of their role.

Solution: Add the following code to your functions.php file:

<?php
add_filter( 'login_redirect', 'ha_login_redirect_by_role', 10, 3 );

function ha_login_redirect_by_role( $redirect_to, $requested_redirect_to, $user ) {
    if ( is_wp_error( $user ) || ! isset( $user->roles ) ) {
        return $redirect_to;
    }

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

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

    if ( in_array( 'subscriber', $user->roles ) ) {
        return get_edit_user_link( $user->ID );
    }

    return home_url();
}

NOTE: The login_redirect filter receives three arguments: the default redirect URL, the originally requested URL, and a WP_User object (or WP_Error on failed login). Always check is_wp_error( $user ) first — if authentication failed, accessing $user->roles will cause a fatal error. The final return home_url() covers any role not listed above.