Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In asking a question about hooks and redirects, I was advised to use wp_redirect in place of the PHP header function. Just wondering why wp_redirect is preferable?

share|improve this question

2 Answers 2

See the source. It has some additional logic for IIS servers, as well as some hooks. It is also pluggable function, so it might be redefined.

Overall it's just more flexible and gives other developers more options to work with your code, unavailable if you just hardcode things.

share|improve this answer
    
beat me by seconds. with closely the same answer. +1 on yours :) –  kaiser Mar 24 '11 at 15:18
    
I gave you both a bump. However, this doesn't sound very good: "This causes problems on IIS and some FastCGI setups": core.trac.wordpress.org/browser/tags/3.1/wp-includes/… . I run FastCGI on all my sites. –  jnthnclrk Mar 24 '11 at 15:26
1  
Doh, just re-read the if statement, and I guess my set-up is protected. Anyways, I'll try it out. –  jnthnclrk Mar 24 '11 at 15:29
    
@trnsfrmr - the FCGI bug is related to some apache code which is fixed IIRC. So keep cool. For IIS I have no clue and I must admit I don't care. What I want to say is: The comment in that function about a BUG is way outdated and might not play any role at all as of today. However using the wp_redirect function helps preventing re-inventing the wheel. Plugins like Better HTTP Redirects (Wordpress Plugin) work with wp_redirect but wouldn't with header() only. –  hakre May 3 '11 at 23:08

It (wp_redirect fn) is more than just setting the header. Just take a look here what it does before setting a header.

share|improve this answer

Your Answer

 
discard

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.