Hi I'm having problems with wp_redirect. I know it's because content is being served before the redirect, but not sure how to correct this because it's in a shortcode. Could anyone point me in the right direction?
Hi I'm having problems with wp_redirect. I know it's because content is being served before the redirect, but not sure how to correct this because it's in a shortcode. Could anyone point me in the right direction?
Hi Beck,
A server redirection using the add_shortcode function will simply never be possible, as you mentioned it there will be always content served before the shortcode function is triggered.
What you should do instead is a javascript redirection but this is not very sexy.
What exactly are you trying to achieve?
Maybe there's another solution.
Cheers,
Ben
Ok Beck,
If you want it to work with a JS redirection the solution will look like that.
Try it out and let me know how does it go.
Ben
Thanks, after some tinkering I got it to work. Something was wrong previously but now it's fine!
Hi.
I am having the same problem.
Did you manage to make it work with a shortcode?
If so could you post the solution?
Thanks.
Hi there,
After the wp_insert post add this
return '<script type="text/javascript">
<!--
window.location = "http://example.com/blahblahblah"
//-->
</script>';
The problem with this is it's a bit clunky - it will still half load the form submission page and then redirect after. But that is fine for what I needed.
This topic has been closed to new replies.