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 user to original url after login?

You can do that easily. You just need to specify a redirection parameter.
If you are using a login link on the homepage to go to the login page, then @sisir’s solution is correct.

<?php echo wp_login_url( $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ); ?>

If you are using a custom form on the frontpage, then inside the <form>, make sure you fill in a hidden field with the url to redirect

<input type="hidden" name="redirect_to" value="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>" />

And if you are using wp_login_form() to generate the form, then fill in a parameter – http://codex.wordpress.org/Function_Reference/wp_login_form

<?php
$args = array(
        'echo' => true,
        'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 
        'form_id' => 'loginform',
        'label_username' => __( 'Username' ),
        'label_password' => __( 'Password' ),
        'label_remember' => __( 'Remember Me' ),
        'label_log_in' => __( 'Log In' ),
        'id_username' => 'user_login',
        'id_password' => 'user_pass',
        'id_remember' => 'rememberme',
        'id_submit' => 'wp-submit',
        'remember' => true,
        'value_username' => NULL,
        'value_remember' => false );

wp_login_form( $args );
?>

Change other parameters as per what you have or need.

Related Posts:

  1. Redirect user to original url after login?
  2. How to redirect after login getting a variable from url (for example with the language)
  3. How to prevent automatic redirection of 404 errors and “incorrect” URLs?
  4. Disable WordPress URL auto complete
  5. Disable ONLY URL auto complete, not the whole canonical URL system
  6. Login redirect to previous page
  7. Redirect to referring page after logging in
  8. User redirect to destination URL after login
  9. check first time login only
  10. How to change the default logout link on WordPress Admin
  11. How to redirect after login, the working way?
  12. Password change when the user login first time
  13. Custom login form redirect to external site
  14. Redirecting WordPress /.htaccess / HSTS / SSL
  15. handling login/logout redirects
  16. Why does WordPress automatically redirect URLs with the parameter “name=” to a different page?
  17. Restrict Access to wp-login.php
  18. How to setup 301 redirects for multiple query string URLs?
  19. Using `auth_redirect` : keeps asking me to login even when I’m logged in
  20. Redirect users after first login
  21. Stop unwanted WP redirection to new url
  22. Redirect to current page after wordpress login
  23. How does WordPress redirect to WooCommerce shop page? [closed]
  24. WP redirects all pages from new domain to old domain
  25. wp-login.php — redirect logged in users to custom URL
  26. Redirect user after login/registration globally
  27. Redirect to login page
  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. Does WordPress automatically redirect url without parent slug?
  32. How to redirect user to specific page based on the input password
  33. How do I redirect a user when he is logged in after clicking on a menu
  34. How to redirect visitor to a custom URL using PHP code in functions.php
  35. How to modify the Register link in the login page?
  36. Redirect home to another page with htaccess
  37. Changing “Lost Password Email Link” to custom password reset page
  38. Why does wp_redirect strip out %0A (url encoded new line character) and how do I make it stop?
  39. How to redirect user to a specific page based on username?
  40. Redirect after password update
  41. How to redirect user after login to a specific page?
  42. Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
  43. How to redirect URL with subfolder to the same URL but without subfolder?
  44. Redirect when accessing /login when logged in
  45. How to redirect a page into file?
  46. If User is NOT Logged in and Page ID is not 6 – Redirect to Login
  47. Redirect to Current Page after Login
  48. How can I replace my primary url globally with a parked one?
  49. How to include error message on login
  50. Login redirect problem
  51. URL redirect problem
  52. How to redirect on login to a specific page if a specific meta user is empty
  53. Adding rewrite rule dynamically for search results redirecting to 404 URL
  54. redirect Login problems
  55. How to redirect to clean links with this code
  56. Redirect user to previous page after signup from custom form
  57. How can I force the user to log in, even if they’re already authenticated?
  58. User is logged in after Stripe payment, then redirected, but is then logged out again
  59. reducing number of URL Redirects and increasing speed
  60. Login Redirect – Multiple Scenarios
  61. WooCommerce – Redirect to a product after login
  62. Usage of the login_redirect filter
  63. URL masking of subdomain to main domain using .htaccess
  64. Login/Register redirect user with message
  65. Disable WordPress URL auto complete
  66. Prevent users from going to wordpress profile after login
  67. Redirect non existing page to frontpage
  68. store URL global before we redirect
  69. Custom form redirect after login
  70. Custom redirect user after login based on metadata
  71. Custom Login Form – Redirect user to login page if not logged in
  72. Redirection on Custom page
  73. WP_List_table with form of method=GET redirects to wrong url after submit
  74. Redirect old URL (with different post ID) to new URL
  75. How to fix automatic redirects?
  76. Redirect user to specific link after login
  77. My redirect URL doesn’t show any pages on my website [closed]
  78. Load function with login_redirect
  79. Prevent “/login” to redirect to “/wp-login”
  80. Redirect User to login page
  81. All URLs Redirect to Main Page
  82. How to redirect user after login to the page called by his first name?
  83. redirect doesn’t work while using example code
  84. Preventing Canonical Redirect for CDN
  85. Why I am not able to direct user to my blog section without login?
  86. Redirect After Login Error
  87. Redirect certain pages if user logged in
  88. Force User Login
  89. wp_login_form redirect
  90. custom login form redirect problem
  91. Login redirect to previous page
  92. CPU overload spam – redirect link to wp-admin and new post
  93. Trying to re-direct users to specific page based on an ACF variable
  94. URL redirection
  95. Disable redirect to homepage after successful Login, Stay on Current Page
  96. Redirect to custom login page if not logged in and redirect to home if logged in user try to login, how?
  97. wp_login_form() redirect same page
  98. How force WordPress redirect to current custom page after login
  99. Hide a Post everywhere except on redirect
  100. Conditional Login Redirect
Categories redirect Tags login, redirect, urls
Pop-up successful message in Fancybox? [closed]
Adding menu items?

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