views:

194

answers:

2

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?

+2  A: 

Try adding a die() after the header command.

Pekka
No dice, the redirect still doesn't occur.
Kristopher
+1  A: 

My mistake; it was redirecting properly. It had to do with "redirect_canonical" redirecting to somewhere I wasn't intending it to.

Kristopher