[英]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.