开发者

header redirect in Wordpress Plugin?

开发者 https://www.devze.com 2022-12-21 08:49 出处:网络
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

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

精彩评论

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