WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The plugin I am working on contains shortcodes with forms on them. Upon form submission (POST), I do some database work, and then planned on redirecting to another page after the db work is complete. When I attempt this, I get the "Headers Already Sent" warning. Within the shortcode function, how do I call my redirect sooner than get_headers? Do I need to use some separate callback function?

share|improve this question
up vote 2 down vote accepted

You have to hook an earlier action to check if the form was submitted. Something like:

function wpa_process_form(){
  if( isset( $_POST['my_form_data'] ) ){
      // process form and redirect
add_action( 'init', 'wpa_process_form' );
share|improve this answer
And this is another function that is tied to init, correct? Not my same shortcode function? – ClockwiseQ May 27 '13 at 19:11
correct, separate from your shortcode function. – Milo May 27 '13 at 19:15
THANKS A MILLION!!! Worked like a charm! – ClockwiseQ May 27 '13 at 19:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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