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_to not Including Hashtag from URL

function after_login_redirect_to_destination(){
    if (!is_user_logged_in() && !is_home()){
        $redirect = home_url() . '/wp-login.php?redirect_to=' . urlencode( $_SERVER['REQUEST_URI'] );
        wp_redirect( $redirect );
        exit;
    }
}
add_action( 'wp', 'after_login_redirect_to_destination', 3 );

the above sample code works and redirect to the login page and after successfull login it will redirect to home page. Whenever a non-logged in user try to access the home page, it will redirect to the login page and after successfull login then it will redirect back to destination page. Here the destination page(home page in this case) . You can modify the code above to your redirect to your custom login page and after success it will then redirect to the current page you were

Hope that helps!

Related Posts:

  1. Action wp_login_failed not working if only one field is filled out
  2. Change register form action url
  3. Restricting frontend acess based on user role otherwise redirect to login form
  4. wp_get_referer not working properly after wp_redirect
  5. Login redirects and query strings
  6. How To Change Wp Register/Login URL Permanently To My Custom Page
  7. Adding rewrite rule dynamically for search results redirecting to 404 URL
  8. How can I login as admin after redirect to custom login page
  9. Redirect wp-login
  10. Changed Wordress Address URL Accidently
  11. Do more action after login successfully
  12. How to redirect home page to another page after login for all user?
  13. Hide Author page from others
  14. Require re-login when logged-in user attempts to access restricted page
  15. This webpage has a redirect loop issue
  16. Trying to re-direct users to specific page based on an ACF variable
  17. WordPress site login Redirect
  18. Problem in auto login after registration
  19. WordPress Redirect After logging
  20. A way to redirect users when they log in based on their current page
  21. Remember me doesn’t work with www?
  22. Trim the repeated value in URL
  23. redirect not logged in users to specific page and redirect them back where they come from
  24. Login form- no feedback
  25. Can’t access wordpress mgt dashboard until propogation finished?
  26. Increase of failed login attempts, brute force attacks? [closed]
  27. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  28. wp_signon() does not authenticate user guidance needed
  29. How to pass users back and forth using session data?
  30. Avoid to load default WP styles in login screen
  31. Send reset password link to user from custom lost password form
  32. template_redirect to accompany with a shortcode
  33. How long do users stay logged in if they DON’T check remember me?
  34. How does WordPress track that a certain User is Logged-In
  35. 2 wordpress blogs with 1 users table and 1 login
  36. How can i add validation to this login form with out it redirecting to the wp-login.php page
  37. Bootstrap Modal as login page
  38. Custom login page always redirecting to wp-login.php
  39. Force users to register in order to view website [duplicate]
  40. auto login after registeration for wp-members plugin
  41. Passing username to login screen
  42. Sniffing wordpress user’s credentials
  43. v5.6.2 User cannot stay logged in – wordpress_test cookie placed but not auth cookies
  44. Redirect user to previous page after signup from custom form
  45. How to set JWT token with PHP on successful login?
  46. Facebook login for private group members
  47. WordPress error on log out ‘Not Permitted’ and can’t log out
  48. How can I change the email sender name from wordpress to (myblogname) on the “lost password” email?
  49. Changed primary domain and now wordpress login won’t work
  50. Add logout link when logged in, make it disappear when logged out?
  51. Keep user session with custom implementation of user login
  52. Forcing frontend login with UI switch
  53. Sidebar login widget with error print, returns an error
  54. Login without Password
  55. Exclude login page from custom maintenance code
  56. Temporarily locked out … how long is a “short while”?
  57. Change default login auth
  58. I can’t access my WordPress dashboard – shows Warning message [closed]
  59. Add html to wp_login_form
  60. Access log “POST /wp-login.php HTTP/1.0” 400
  61. Are login functions considered part of the WP backend?
  62. SQL – Remove All The Users and Create A New User With Admin Role Via PhpMyAdmin
  63. Can I protect a type of content site-wide with a single password?
  64. Sign in with social media accounts without creating a WP account [closed]
  65. WordPress login form script
  66. WordPress authentication using custom php?
  67. what is the best and safest way to allow users to register to site
  68. ERROR: Cookies are blocked due to unexpected output (no FTP access)
  69. Sharing a logged in session with a custom subdmain site?
  70. How do I change the language of the login page to Arabic?
  71. MAMP localhost wordpress site, not possible to sign in, username and password are correct
  72. Login issues wordpress page
  73. How to post frontend login form to a different authentication script from wp-login?
  74. Make WordPress User Name be the Company Name when Registering (not the default ‘first name’ last name’ email address’)
  75. Why do I have a reauth=1 redirection loop when I try to log in to WordPress hosted on AWS Fargate?
  76. Login form does not store/remember/suggest users password
  77. Problem with is_user_logged_in() function in some pages
  78. Confused – can’t access wordpress dashboard or site that has been published
  79. wordpress login loop and session problem
  80. unable to Login to Admin
  81. WordPress login loop on proxy setup with SSL – Apache proxy to IIS
  82. ERROR: Cookies are blocked due to unexpected output – ultimate solution
  83. How to dequeue the default CSS styles on the wp-login.php page?
  84. confirmation email is send from my local host registration of a user but mail will not display in there email account?
  85. Server error after log in
  86. How do I resolve my inability to login to WordPress dashboard? [duplicate]
  87. Chrome incorrectly displaying WP login as ‘not fully secure’
  88. Changed from HTTP to HTTP, can login no longer login
  89. Hide wp-login.php but not the widget
  90. Without user loging inner page is disable wordpress [duplicate]
  91. Registration and Login form
  92. WordPress and Magento: let WordPress manage user registration and logins?
  93. Share login status across subdomains without network
  94. How to change the login URL
  95. Click on banner to register to the blog
  96. Redirect drafted post of custom post type to URL?
  97. “user not registered” when trying to login and “There has been a critical error” message on site
  98. Cannot find redirect – WordPress behind HTTPS proxy (Cloudfront)
  99. Where does the redirect from shortlink to permalink happen?
  100. generate an array of user login date using update_user_meta();
Categories login Tags login, template-redirect, urls, wp-redirect
Use fetch_feed(); Totally Outside of WordPress?
trying to locate the correct file to edit my internal linking anchor tags

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