[英]WP_redirect not working (header already sent in pluggable.php)
我想在模板文件中使用此代码:
if ( wp_is_mobile() ) {
wp_redirect( "/shop-mobile", $status );
}
但它说:标头已经由/ filewithcode在... / wp_includes / pluggable.php中的第1196行发送
我试图从空格中清除可插拔文档。.还有什么可能是这里的问题? 谢谢
“要解决“已发送的标题”问题,您需要将所有表单处理从页面底部移至页面顶部。如果需要调用wp_redirect(),则必须先进行调用,然后再打印任何内容-HTML或其他内容-页面。”
参考: https : //wordpress.stackexchange.com/questions/81566/wp-redirect-headers-already-sent-after-front-end-submission-form
您可以阅读以获取有关此问题的更多解释
确保wp_redirect函数上方的代码尚未将标头信息发送到服务器。
标头信息将在以下某些情况下发送到服务器:
打印,回显
<?php or space after ?>
之前的<?php or space after ?>
使用以下命令检查标题是否已发送:
if (headers_sent()) {
die("Redirect failed. Please click on this link: <a href=...>");
}
else{
exit(header("Location:/test.php"));
}
请参考以下链接以获取更多指导。 如何修复PHP中的“标头已发送”错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.