I am displaying a form on the public side using shortcode.The shortcode is included on Post add_new, located at http://localhost/wordpress/add_new/. On successful saving of form data, I need the page to either 1) change the page's location and show a message of successful completion, or show a message of successful completion on page add_new.

This is my shortcode:

add_shortcode( 'show_INT_form', function() {
    $int_class = new int_class;

    if ( isset( $_REQUEST['int_prefix'] ) && isset( $_REQUEST['int_suffix'] ) ) { 
        // ???? Area X
        // What do I do here?
        // ????
    else {
        $ret = $int_class->public_form(); // function that loads the form onto the page

    return $ret;
} );

How can I have the add_new page load another page?

I have seen sample code simply echoing <meta http-equiv='refresh' content='0;url=page_to_load' /> in Area X located in the comments in the code above. I have tried this, and it works, but is this proper procedure?

I have not tried other methods since I don't know how to work around the function and class scope. How could I call a new event listener (such as add_action( 'send_headers' ) ) outside of my add_shortcode function and pass it an argument, such as a 'success' or 'error' message?

1 Answer 1


Move your form processing code outside the shortcode so you can hook it to an earlier action before headers are sent, then you can do whatever redirection you need to after the form is processed.

function process_int_form(){
    if ( isset( $_REQUEST['int_prefix'] ) && isset( $_REQUEST['int_suffix'] ) ) {
        // process form
        wp_redirect( home_url( $_SERVER['REQUEST_URI'] ) );
add_action( 'init', 'process_int_form' );
  • Thank you for your answer. Won't this function be called every time any and every page is loaded? Commented Oct 11, 2013 at 5:12
  • yes, but there is no way you'd be able to detect a performance hit
    – Milo
    Commented Oct 11, 2013 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.