我想在模板文件中使用此代码:WP_redirect不工作(头已经pluggable.php发送)
if (wp_is_mobile()) {
wp_redirect("/shop-mobile", $status);
}
但它说:头部已经通过/ filewithcode在.../wp_includes /发pluggable.php on line 1196
我试图从空间清理可插入文档..还有什么可能是这里的问题?谢谢
我想在模板文件中使用此代码:WP_redirect不工作(头已经pluggable.php发送)
if (wp_is_mobile()) {
wp_redirect("/shop-mobile", $status);
}
但它说:头部已经通过/ filewithcode在.../wp_includes /发pluggable.php on line 1196
我试图从空间清理可插入文档..还有什么可能是这里的问题?谢谢
“要解决”已发送头文件“问题,您需要将所有表单处理从页面底部移至页面顶部。如果您需要调用wp_redirect(),您必须在打印任何内容(HTML或其他内容)之前调用该页面。“
你能看懂这个问题
的更多的解释确保上述wp_redirect函数的代码尚未发送的报头信息到服务器。
页眉信息将在以下一些情况下被发送到服务器:
打印,回声如果头正在
空间之前<?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