开发者

header redirect in Wordpress Plugin?

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 snip开发者_如何转开发pet:

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?


Try adding a die() after the header command.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜