The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use WordPress’s login_redirect filter to choose where a user goes after a successful login. Its callback receives the proposed destination, the originally requested destination, and the user value; use that passed user rather than relying on the $current_user global, which may not be available yet.
Choose the post-login destination with login_redirect
Add a callback in a site-specific plugin or your theme’s functions.php. A site-specific plugin keeps the rule active if you change themes. This example leaves the proposed destination unchanged for administrators and sends other valid users to the site homepage:
As an Amazon Associate I earn from qualifying purchases.
function my_login_redirect( $redirect_to, $requested_redirect_to, $user ) {
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'administrator', $user->roles, true ) ) {
return $redirect_to;
}
return home_url( '/' );
}
return $redirect_to;
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
The role rule is a site policy, not WordPress’s default behavior. Change the condition and returned URL to match your intended flow. The final 3 tells WordPress to pass all three filter arguments. The callback returns a URL; WordPress’s login flow performs the redirect. See the WordPress login_redirect reference.
Recommended Free Tools
Preserve requested destinations when needed
When someone tries to open a protected page while logged out, WordPress’s auth_redirect() flow sends them to the login screen and returns them to the page they originally requested after authentication. Avoid overriding that journey without a clear reason. The callback receives both $redirect_to, the proposed destination, and $requested_redirect_to, the originally requested destination; preserve the appropriate value when your site relies on it.
#1 Best Overall
You can also pass a destination when generating a login URL with wp_login_url(). Its $redirect argument should be an absolute URL, and the documentation recommends site_url() for best results. Consult the WordPress wp_login_url() reference and WordPress auth_redirect() reference.
Route different user roles deliberately
For role-specific routing, test the roles on the passed $user object and return a deliberate destination for each case. A user may have more than one role, so decide how your rules handle that possibility; the order of your conditions determines which matching rule wins.
Rank #2
- Keep an intentional fallback for roles or user values your rules do not handle.
- Return the proposed destination for users whose requested-page or login flow should remain unchanged.
- Use site-local destinations where possible, and do not trust a URL supplied by a request without validating it.
The filter’s user argument can be a WP_User or a WP_Error, so check that it has the user properties your code needs before inspecting roles. The hook reference documents the arguments and behavior: WordPress Developer Resources: login_redirect.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Understand URL safety and redirect functions
Returning a destination from login_redirect is different from sending a redirect response yourself. If your own code needs to issue a redirect to a destination that may be influenced by a request, use wp_safe_redirect():
wp_safe_redirect( $url );
exit;
For an absolute URL, wp_safe_redirect() checks the destination host against the allowed hosts and falls back to the admin URL if the host is not permitted. Its default response is HTTP 302. It does not stop PHP execution, so WordPress says it should almost always be followed by exit. See the WordPress wp_safe_redirect() reference.
wp_redirect() also does not stop execution automatically, but it does not validate that the destination host is allowed. Do not use it with an untrusted, user-supplied URL. The WordPress wp_redirect() reference explains its behavior.
Use the hook that matches the job
Use login_redirect when you need to select the URL after login. The separate wp_login action fires after a successful login and runs immediately after WordPress sets the authentication cookie during wp_signon(); it is not the direct destination-selection hook. See the WordPress wp_login reference.
When to use a plugin instead of custom code
A plugin with configurable post-login routing may suit a site that prefers settings to maintaining a callback. Before relying on one, check whether it preserves requested destinations, supports the needed role or user rules, handles unsafe external destinations appropriately, remains maintained, and works with your login or membership setup. Custom code offers direct control, but someone must maintain it as the site changes.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




