WordPress.org

Ready to get started?Download WordPress

Forums

wp_redirect after insert post with shortcode (6 posts)

  1. becskr
    Member
    Posted 2 years ago #

    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?

    http://pastebin.com/gKL7FX78

  2. Ben
    Member
    Posted 2 years ago #

    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

  3. Ben
    Member
    Posted 2 years ago #

    Ok Beck,

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

    http://pastebin.com/L6xrvN8h

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

    Ben

  4. becskr
    Member
    Posted 2 years ago #

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

  5. skapator
    Member
    Posted 1 year ago #

    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.

  6. becskr
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic