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

    https://pastebin.com/gKL7FX78

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.

    Cheers,
    Ben

    Ok Beck,

    If you want it to work with a JS redirection the solution will look like that.

    https://pastebin.com/L6xrvN8h

    Try it out and let me know how does it go.

    Ben

    Thread Starter becskr

    (@becskr)

    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.

    Thread Starter becskr

    (@becskr)

    Hi there,

    After the wp_insert post add this

    return ‘<script type=”text/javascript”>
    <!–
    window.location = “https://example.com/blahblahblah&#8221;
    //–>
    </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.

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