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

Login form from shortcode doesn’t redirect after successful login

The problem you’re facing is because of the nature of the WordPress redirect. It uses what is called a safe redirect, namely with the function wp_safe_redirect(). This restricts redirects to local URLs only.

Your work around for this is the following where you jump into the login redirect filter and perform your desired redirection then, before WordPress does it for you.

Keep all your previous code as-is, and add the following:


add_filter( 'login_redirect', 'my_login_form_redirect', 0, 1 );

function my_login_form_redirect( $redirect ) {
    if ( !empty( $_POST[ 'redirect_to' ] ) && filter_var( $_POST[ 'redirect_to' ], FILTER_VALIDATE_URL ) ) {
        wp_redirect( $_POST[ 'redirect_to' ] );
    }
    return $redirect; 
}

Related Posts:

  1. Set redirect for need login
  2. Redirect function inside a Shortcode
  3. Use another action instead of the shortcode API to display the last time a user logged in
  4. redirect if shortcode exists
  5. Modifying the wordpress login page and then referencing it with a shortcode problem
  6. Processing a login/register form before shortcodes are rendered?
  7. How to create a custom shortcode for custom login form?
  8. i want to show a modal when user lands on home page very first time
  9. Redirect per shortcode if user is logged in
  10. Custom Login in Shortcode got error
  11. Which method to use when deleting posts from the front-end
  12. Add an access code form to call a unique page based on page without registration
  13. convert it into short code & explan how? [closed]
  14. Enqueue Scripts / Styles when shortcode is present
  15. Conditionally Loading JavaScript/CSS for Shortcodes
  16. What does extract( shortcode_atts( array( do?
  17. How do I escape a ‘]’ in a short code?
  18. Pass boolean value in shortcode
  19. Show shortcode without executing it
  20. Shortcode always displaying at the top of the page
  21. Redirect user to original url after login?
  22. How to create a shortcode with 1 parameter (atts)
  23. how to show the syntax of a shortcode
  24. Custom shortcode being executed when saving page in wp-admin
  25. Change appearance of shortcode text inside editor
  26. current_shortcode() – detect currently used shortcode
  27. shortcodes output before content [duplicate]
  28. WordPress plugin shortcode not working
  29. How to add stylesheets only to pages with specific shortcode?
  30. Login redirect to previous page
  31. Using get_option() in JavaScript
  32. Shortcode empty attribute
  33. How does a shortcode work?
  34. Shortcode outputs at the top of the_content
  35. the_excerpt and shortcodes
  36. Using wp_editor in shortcode
  37. Remove wpautop from shortcode content / remove whitespace in buffering
  38. Redirect to referring page after logging in
  39. Get current post id witout passing in shortcode
  40. Why are you using add_action for shortcode?
  41. How to get URL param to shortcode?
  42. How to add multiple buttons to TinyMCE?
  43. Check if post/page has gallery?
  44. Get first video from the post (both embed and video shortcodes)
  45. check first time login only
  46. Get shortcode name from within it’s callback function? [duplicate]
  47. Wordspress add into my javascripts
  48. How to change the default logout link on WordPress Admin
  49. Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
  50. How do I create a Shortcode that returns text if domain is .com, not .co.uk
  51. Using preg_replace to separate gallery from the_content?
  52. Remove specific shortcode from get_the_content()
  53. How to display the site name in a WordPress page, or post
  54. Hide/show content starting in the middle of a paragraph
  55. Combining shortcode and get_template_part
  56. How can I put a wp_redirect into a shortcode?
  57. Escaping quotes from shortcode attributes
  58. Run visual composer code in php page
  59. short code output too early
  60. Shortcode in shortcode: How to append variable?
  61. Remove wptexturize from a shortcode?
  62. How can i put an array as variable in shortcode_atts?
  63. Autoembeds don’t work with paragraphs
  64. Table of Contents with a shortcode
  65. Create custom [sourcecode] shortcode, the right way?
  66. TED talks shortcode not working
  67. Allowing shortcodes inside attributes
  68. What is the best way to enable nested shortcodes?
  69. Tinymce – How to hook before or after live shortcodes rendering?
  70. How to customize a shortcode using the customizer
  71. Native “playlist” shortcode random playing… How?
  72. How to Output HTML tags in do_shortcode?
  73. List of all inbuilt WordPress shortcodes
  74. Nested Shortcode Detection
  75. Shortcode output always showing at top of page
  76. Organizing shortcodes. How to display all of them and their attributes?
  77. How to detect if a Shortcode is being called on a page?
  78. How to redirect after login, the working way?
  79. How to get current page title inside a page itself in a shortcode and in page content
  80. how to have the gallery shortcode output one single UL list instead of several DL?
  81. Implement If-ElseIf-Else-EndIf with short codes
  82. Short code to display a loop
  83. Using shortcode in Post title
  84. using html as shortcode attribute
  85. Masking logout URL
  86. shortcode outputs first before the page content [duplicate]
  87. Password change when the user login first time
  88. Custom login form redirect to external site
  89. How to add ‘class’ attribute into shortcode [audio]?
  90. Make shortcode work with nested double quotes
  91. Get all posts containing a shortcode
  92. How to display the names of users from a specific group with a shortcode?
  93. handling login/logout redirects
  94. WordPress adds br in between my shortcode
  95. Stray closing paragraph tag when using shortcodes
  96. How to display html in a shortcode
  97. Can I strip HTML tags in the “Compare Revisions” screen?
  98. Custom form, shortcode, and submit handler
  99. shortcode inside another shortcode
  100. Automatically add this attribute to the gallery shortcode
Categories shortcode Tags login, redirect, shortcode
Cannot save CPT meta box
Port existing Bootstrap site to WordPress?

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