Redirection using PHP footer in Worpress
Question by The Waves
I have a question about timed redirects in PHP – specifically in wordpress.
We have setup a site using a free Woothemes placeholder theme, it is very limited. But that is OK – the site is simple.
After 20 seconds I would like the page to redirect to another URL – would it be possible to insert some code into footer.php to do this? I have found what looks like the right code:
// Redirect with a delay:
header('Refresh: 20; url=http://www.example.org/');
Can this be inserted antwhere in footer.php?
Any input is welcome.
Answer by Starx
Yes, it can be inserted, but in case some HTML is already by the server you will receive an warning such as header already sent by .....
and the redirection will not function as it should.
Instead you can perform such by clearing everything in the output buffer using ob_clear() that is to be printed and then send the redirection header.
Example:
if($casespecial==true) {
ob_clean(); //make sure nothing is outputed to the browser
header('Refresh: 20; url=http://www.example.org/'); //now send the header param
//After wards, you can resume your normal code and output the template as you require
.
.
.
}