2015-07-12 70 views
1

我想在模板文件中使用此代码:WP_redirect不工作(头已经pluggable.php发送)

if (wp_is_mobile()) { 
wp_redirect("/shop-mobile", $status); 
} 

但它说:头部已经通过/ filewithcode在.../wp_includes /发pluggable.php on line 1196

我试图从空间清理可插入文档..还有什么可能是这里的问题?谢谢

回答

0

的更多的解释确保上述wp_redirect函数的代码尚未发送的报头信息到服务器。

页眉信息将在以下一些情况下被发送到服务器:

  1. 打印,回声如果头正在

  2. 空间之前<?php or space after ?>

检查已发送使用:

if (headers_sent()) { 
    die("Redirect failed. Please click on this link: <a href=...>"); 
} 
else{ 
    exit(header("Location:/test.php")); 
} 

请参阅下面的链接以获取进一步指导。 How to fix "Headers already sent" error in PHP