header redirect in Wordpress Plugin?

Posted by Kristopher on Stack Overflow See other posts from Stack Overflow or by Kristopher
Published on 2010-02-25T00:22:50Z Indexed on 2010/06/13 13:32 UTC
Read the original article Hit count: 187

Filed under:
|
|

I'm writing a Wordpress plugin, and based on certain circumstances, I want to redirect to a different page, but the redirect never happens. headers_sent() returns false. I'm using the pre_get_posts hook. Here is a small snippet:

function test_redirect()
{
    header("Location: http://www.cnn.com/");
}

add_action('pre_get_posts', 'test_redirect');

The redirect never happens, and no errors are reported on the page or in the error log. Why can't I redirect?

© Stack Overflow or respective owner

Related posts about php

Related posts about Wordpress