Support » Fixing WordPress » wp_redirect after insert post with shortcode

  • 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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.


    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.


    Thanks, after some tinkering I got it to work. Something was wrong previously but now it’s fine!

    I am having the same problem.
    Did you manage to make it work with a shortcode?
    If so could you post the solution?


    Hi there,

    After the wp_insert post add this

    return ‘<script type=”text/javascript”>
    window.location = “”

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp_redirect after insert post with shortcode’ is closed to new replies.