Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

redirect doesn’t work while using example code

You can use the login_redirect filter to do this. One of the parameters is $request, which is the URL the user is coming from

Use the below in your active theme’s functions.php file to make this work.

function wpse126853_redirect_to_request( $redirect_to, $request, $user ) {
    // instead of using $redirect_to we're redirecting back to $request
    return $request;
}
add_filter( 'login_redirect', 'wpse126853_redirect_to_request', 10, 3 );

You can use the filter for distinguishing redirect destinations by user roles. Take a look at the documentation for a deeper insight into that.

Related Posts:

  1. Custom login form redirect to external site
  2. Redirect user after login/registration globally
  3. Redirect when accessing /login when logged in
  4. Disable redirect to homepage after successful Login, Stay on Current Page
  5. wp_login_form() redirect same page
  6. Determine user destination on wp-login.php
  7. Redirect after login when WordPress in subdirectory
  8. Login redirects to home page and doesn’t log in
  9. Login Form Redirection
  10. Redirect user to login and then to page where they came from
  11. Redirect user to original url after login?
  12. Login redirect to previous page
  13. Redirect to referring page after logging in
  14. check first time login only
  15. How to change the default logout link on WordPress Admin
  16. How to redirect after login, the working way?
  17. Password change when the user login first time
  18. handling login/logout redirects
  19. Clarification on auth_redirect()
  20. How to redirect all requests to wp-login.php?
  21. Restrict Access to wp-login.php
  22. Using `auth_redirect` : keeps asking me to login even when I’m logged in
  23. Redirect users after first login
  24. Redirect to current page after wordpress login
  25. wp-login.php — redirect logged in users to custom URL
  26. Redirect to login page
  27. Remove lost password form and URL
  28. You do not have sufficient permissions to access this page
  29. Redirect user after logout
  30. how to do logout redirect to current url
  31. How to redirect user to specific page based on the input password
  32. How do I redirect a user when he is logged in after clicking on a menu
  33. How to auto login after registration? [duplicate]
  34. Change ‘Back To Website’ link in wp-login.php
  35. Redirect away from login page
  36. How to modify the Register link in the login page?
  37. Changing “Lost Password Email Link” to custom password reset page
  38. How to redirect user to a specific page based on username?
  39. Redirect after password update
  40. How to redirect user after login to a specific page?
  41. Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
  42. How to redirect after login getting a variable from url (for example with the language)
  43. If User is NOT Logged in and Page ID is not 6 – Redirect to Login
  44. Redirect to Current Page after Login
  45. How to include error message on login
  46. Login redirect problem
  47. How to redirect on login to a specific page if a specific meta user is empty
  48. redirect Login problems
  49. wp-admin – 404 after custom login form
  50. How to fix ‘WordPress redirection loop problem in wp-login.php page’?
  51. Redirect user to previous page after signup from custom form
  52. How can I force the user to log in, even if they’re already authenticated?
  53. User is logged in after Stripe payment, then redirected, but is then logged out again
  54. Login Redirect – Multiple Scenarios
  55. WooCommerce – Redirect to a product after login
  56. Usage of the login_redirect filter
  57. Login/Register redirect user with message
  58. Redirect user to original url after login?
  59. Redirect outside WP after login
  60. Prevent users from going to wordpress profile after login
  61. Custom form redirect after login
  62. Custom redirect user after login based on metadata
  63. wp_login_form redirect problem
  64. Custom Login Form – Redirect user to login page if not logged in
  65. Redirection on Custom page
  66. Redirect user to specific link after login
  67. Load function with login_redirect
  68. How to redirect wp_login_form to new page after user loged in?
  69. Prevent “/login” to redirect to “/wp-login”
  70. Redirect User to login page
  71. All URLs Redirect to Main Page
  72. How to redirect user after login to the page called by his first name?
  73. Why I am not able to direct user to my blog section without login?
  74. Redirect After Login Error
  75. Redirect certain pages if user logged in
  76. Force User Login
  77. wp_login_form redirect
  78. custom login form redirect problem
  79. Login redirect to previous page
  80. Trying to re-direct users to specific page based on an ACF variable
  81. Redirect to custom login page if not logged in and redirect to home if logged in user try to login, how?
  82. How force WordPress redirect to current custom page after login
  83. Hide a Post everywhere except on redirect
  84. Conditional Login Redirect
  85. Keep the old referrer after failed login
  86. Redirect user after login to prior page through a wp_login hook
  87. How can force redirected to login for two or more pages to view or access
  88. Infinite loop when logging out using custom login form
  89. How to redirect user to Referrer Page using wp_signon in Custom Login Page in WordPress
  90. HOW do you Redirect buddypress login to EDIT tab not PROFILE tab on profile page? [closed]
  91. WordPress not loggin user and redirecting after custom registration
  92. redirect_to ignoring the SSL
  93. Redirect user on login using extra field value on login form
  94. Woocommerce login to specific page or referrer
  95. wp-login.php redirect problem
  96. login redirect problem – db charset issue?
  97. Custom login-form redirect
  98. How to modify the WordPress comes with redirect
  99. Conditional redirect on login using referring URL
  100. Redirect problem: How to redirect to the original URL after login
Categories redirect Tags login, redirect, wp-login-form
Appearance > Menus > Left Sidebar > Add Toggle
How we stop caching of particular div when i am using w3 total cache plugin? [closed]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress