0

I have the following action and function. Ultimately i'm trying to get access to value $processArtwork in my template. One option is pass the value via the querystring. However the following results in

"Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxx/europeanpaintings.rpc-staging.com/wp-includes/formatting.php:1021) in /home/xxxxx/mysite.com/wp-includes/pluggable.php on line 1228"

add_action('init', 'process_artwork');

function process_artwork(){
    if(isset($_GET['ss-process'])) {

                $newUrl = "/process-artwork/?processedArtwork=56";

                wp_redirect( $newURL ); 
                exit;
    }
}
  • You don't have to wait for init to $_GET what's in it. – jgraup Dec 22 '15 at 23:45
1

You do not get that error because it runs inside a function, but because the headers have already been send. This means your server already has send some information about the page to the client, thus is it unable to change it's headers (headers are the first thing that gets send). This mostly happens after something gets echo'ed.

There are a few things you can do to prevent this from happening:

  • Choose another event that gets triggered before the headers are send
  • Remove any echo'ed text or HTML before the redirect
  • Check if there is no whitespace (spaces, enters, tabs) between the the start of your file and the <?php tag.
  • Change your server configration to send the headers later (this can be tricky or inpossible).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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