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?

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.

  • beat me by seconds. with closely the same answer. +1 on yours :)
    – kaiser
    Mar 24, 2011 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, 2011 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, 2011 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, 2011 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.

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.