WordPress sends every user to the admin dashboard after login by default, regardless of whether that user has any reason to be in the admin. WooCommerce customers, membership site subscribers, and front-end-only users all land in /wp-admin/ after logging in, which is disorienting when you’ve built a front-end member area or account portal for them. The login_redirect filter lets you route each user role to the appropriate destination immediately after authentication.
The Code
Add this to your functions.php or a site-specific plugin. The filter receives three arguments: the current redirect destination, the requested redirect URL from the login form, and the WP_User object of the user who just logged in.
Honouring Explicit Redirects
The first check respects any explicit redirect_to parameter that was passed to the login URL. This covers the common case where a user was redirected to login because they tried to access a specific page, after logging in, they should land on that page rather than whatever role-based destination the snippet would send them to. The check compares the requested redirect against the plain admin URL, if it’s different, something explicitly requested that destination and should be honoured.
Role-Based Routing
The routing logic uses array_intersect() for roles where multiple roles should share the same destination, administrators and editors both going to the dashboard in the example. in_array() with strict comparison handles roles that map to a single destination.
The order of the role checks matters. PHP evaluates them top to bottom, and a user with multiple roles (which is possible) will match the first applicable condition. Place the most specific or highest-privilege role checks first so they take priority over broader conditions at the bottom.
WooCommerce My Account URL
wc_get_page_permalink( 'myaccount' ) returns the URL of the WooCommerce My Account page as configured in WooCommerce settings. Using this function rather than hardcoding the URL ensures the redirect works correctly even if the My Account page URL is changed in the admin. The function is only available when WooCommerce is active, the snippet doesn’t include a WooCommerce existence check, so add one if WooCommerce is not guaranteed to be active on your site.
Fallback Destination
The final return at the bottom is the catch-all for any role not explicitly handled above, subscribers, custom roles added by plugins, and any future roles. Replace home_url( '/members/' ) with whatever front-end URL makes sense for your lowest-privilege users, a dashboard page, a welcome page, or the homepage.
add_filter( 'login_redirect', function( $redirect_to, $request, $user ) {
// If there's a specific redirect_to URL in the request, honour it
if ( ! empty( $request ) && $request !== admin_url() ) {
return $redirect_to;
}
if ( ! isset( $user->roles ) || ! is_array( $user->roles ) ) {
return $redirect_to;
}
// Administrators and editors go to the dashboard
if ( array_intersect( [ 'administrator', 'editor' ], $user->roles ) ) {
return admin_url();
}
// WooCommerce customers go to My Account
if ( in_array( 'customer', $user->roles, true ) ) {
return wc_get_page_permalink( 'myaccount' );
}
// Authors go to the new post screen
if ( in_array( 'author', $user->roles, true ) ) {
return admin_url( 'post-new.php' );
}
// Subscribers and everyone else go to a specific front-end page
return home_url( '/members/' );
}, 10, 3 );
