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
- convert it into short code & explan how? [closed]
- Enqueue Scripts / Styles when shortcode is present
- Conditionally Loading JavaScript/CSS for Shortcodes
- What does extract( shortcode_atts( array( do?
- How do I escape a ‘]’ in a short code?
- Pass boolean value in shortcode
- Show shortcode without executing it
- Shortcode always displaying at the top of the page
- Redirect user to original url after login?
- How to create a shortcode with 1 parameter (atts)
- how to show the syntax of a shortcode
- Custom shortcode being executed when saving page in wp-admin
- Change appearance of shortcode text inside editor
- current_shortcode() – detect currently used shortcode
- shortcodes output before content [duplicate]
- WordPress plugin shortcode not working
- How to add stylesheets only to pages with specific shortcode?
- Login redirect to previous page
- Using get_option() in JavaScript
- Shortcode empty attribute
- How does a shortcode work?
- Shortcode outputs at the top of the_content
- the_excerpt and shortcodes
- Using wp_editor in shortcode
- Remove wpautop from shortcode content / remove whitespace in buffering
- Redirect to referring page after logging in
- Get current post id witout passing in shortcode
- Why are you using add_action for shortcode?
- How to get URL param to shortcode?
- How to add multiple buttons to TinyMCE?
- Check if post/page has gallery?
- Get first video from the post (both embed and video shortcodes)
- check first time login only
- Get shortcode name from within it’s callback function? [duplicate]
- Wordspress add into my javascripts
- How to change the default logout link on WordPress Admin
- Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
- How do I create a Shortcode that returns text if domain is .com, not .co.uk
- Using preg_replace to separate gallery from the_content?
- Remove specific shortcode from get_the_content()
- How to display the site name in a WordPress page, or post
- Hide/show content starting in the middle of a paragraph
- Combining shortcode and get_template_part
- How can I put a wp_redirect into a shortcode?
- Escaping quotes from shortcode attributes
- Run visual composer code in php page
- short code output too early
- Shortcode in shortcode: How to append variable?
- Remove wptexturize from a shortcode?
- How can i put an array as variable in shortcode_atts?
- Autoembeds don’t work with paragraphs
- Table of Contents with a shortcode
- Create custom [sourcecode] shortcode, the right way?
- TED talks shortcode not working
- Allowing shortcodes inside attributes
- What is the best way to enable nested shortcodes?
- Tinymce – How to hook before or after live shortcodes rendering?
- How to customize a shortcode using the customizer
- Native “playlist” shortcode random playing… How?
- How to Output HTML tags in do_shortcode?
- List of all inbuilt WordPress shortcodes
- Nested Shortcode Detection
- Shortcode output always showing at top of page
- Organizing shortcodes. How to display all of them and their attributes?
- How to detect if a Shortcode is being called on a page?
- How to redirect after login, the working way?
- How to get current page title inside a page itself in a shortcode and in page content
- how to have the gallery shortcode output one single UL list instead of several DL?
- Implement If-ElseIf-Else-EndIf with short codes
- Short code to display a loop
- Using shortcode in Post title
- using html as shortcode attribute
- Masking logout URL
- shortcode outputs first before the page content [duplicate]
- Password change when the user login first time
- Custom login form redirect to external site
- How to add ‘class’ attribute into shortcode [audio]?
- Make shortcode work with nested double quotes
- Get all posts containing a shortcode
- How to display the names of users from a specific group with a shortcode?
- handling login/logout redirects
- WordPress adds br in between my shortcode
- Stray closing paragraph tag when using shortcodes
- How to display html in a shortcode
- Can I strip HTML tags in the “Compare Revisions” screen?
- Custom form, shortcode, and submit handler
- shortcode inside another shortcode
- Automatically add this attribute to the gallery shortcode