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:
- Set redirect for need login
- Redirect function inside a Shortcode
- Use another action instead of the shortcode API to display the last time a user logged in
- redirect if shortcode exists
- Modifying the wordpress login page and then referencing it with a shortcode problem
- Processing a login/register form before shortcodes are rendered?
- How to create a custom shortcode for custom login form?
- i want to show a modal when user lands on home page very first time
- Redirect per shortcode if user is logged in
- Custom Login in Shortcode got error
- Which method to use when deleting posts from the front-end
- Add an access code form to call a unique page based on page without registration
- Using get_option() in JavaScript
- Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
- How to display the site name in a WordPress page, or post
- How can I put a wp_redirect into a shortcode?
- Native “playlist” shortcode random playing… How?
- Stop strip_shortcodes() stripping content inside shortcodes
- How do i link gallery thumbnails to different url’s using the wp native gallery?
- How to save a shortcode in a Gutenberg custom block?
- Is shortcode_unautop() broken?
- Some doubts about gallery shortcode in WordPress
- Dynamically create shortcodes using add_shortcode and a callback
- How can I make a shortcode from this code?
- Meta tags in shortcode
- Adding PHP/HTML code inside page from custom template
- ShortCode and extra
- How to change page title (from a plugin) in twentytwentyone theme
- WordPress Code Standards and Working $link Parameters In Shortcode
- shortcode get thumbnail size
- Shortcodes Keep Wrapping in
- If you add a shortcode programmatically, but the code isn’t viewed on that request, is it still executed?
- Problem with using custom shortcode with ACF WYSIWYG field
- How to include error message on login
- redirect Login problems
- Populate shortcodes with table data and get next row
- Running shortcode with variable that is modified
- Shortcode is not processed when added to option field using wp_editor
- How to apply an ID to Shortcode Embedded iframe
- WordPress Short code with additional parameter
- How to protect parts of my code from TinyMCE modification when switching from text to visual mode?
- Creating a short code with php inside
- Shortcode output appearing at the top of the page only [duplicate]
- problem with shortcodes nesting
- OOP and WordPress shortcode
- PHP/WordPress — How do I check if Shortcode returns content?
- Convert my php code into shortcode
- Add shortcode with open close function
- Shortcode is not working
- Will a shortcode placed inside a paragraph tag still be valid?
- Why can’t I display attachment_image_src with Custom Size?
- Shortcode Strategy
- Enclosing Shortcode is acting like self-closing
- Shortcode into the same shortcode
- How do I define and register a shortcode function in a namespaced functions.php file?
- Change user meta value with shortcode
- Execute shortcodes in PHP
- A shortcode nested inside a shortcode
- WordPress User ID as Shortcode
- Custom Shortcode + Querying and Ordering Posts using multiple Advanced Custom checkboxes
- call other shortcode in the email contactform7 send [closed]
- Putting a space between the buttons [closed]
- How can I replace content on site generated from plugin without changing plugin
- Dynamic number within shortcode
- How can i strip shortcode from HTML title tag?
- Need help with creating a simple shortcode
- Returning HTML to Shortcode Block
- WP REST API remove the WordPress shortcodes from the JSON wp/v2/posts content->rendered
- Hide download option video shortcode
- WordPress Shorcode Display hierarchical taxonomy [child, parent]
- Shortcode not working in Jetpack Top Posts & Pages widget
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Gutenberg running code only available in front end within shortcode
- Insert HTML in content property and render it using shortcodes
- Shortcode, vs blocks, vs templates – what would you do for choosing or creating custom post data in editor?
- Logout user if click on a custom page link
- Shortcode Attribute not defined
- Convert WordPress shortcodes into plain html
- redirect_to how to make it simply work with get parameter or similar?
- Second attribute of shortcode is not changing why?
- How to modify the WordPress comes with redirect
- Conditional redirect on login using referring URL
- How to make a shortcode with a line break in it parse correctly?
- Plugin Shortcode value in post
- Woocommerce Filter Main Loop by Tag [closed]
- Shortcodes: override a shortcode / change shortcode on the fly
- Separating Custom Template logic
- Remove width and height attributes from [gallery] output
- woocommerce Product shortcode create [closed]
- A number appears inside a div called wpb_wrapper, when I use a custom shortcode
- Help with Shortcode Functionality
- Shortcode Site include in a other
- Why is my ajax live search not working when i use a shortcode to call it?
- How do write this type shortcode? [closed]
- WordPress functions.php shortcode is not working [closed]
- My first WordPress shortcode just returning []
- WordPress shortcode select option not working [closed]
- Working with Shortcode, AJAX, Elementor
- How to exclude some cats from wp_list_categories using shortcut
- How can I create a shortcode that shows a list of categories on the single product page?