国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

幫助中心 >  技術(shù)知識庫 >  虛擬主機 >  虛擬主機常見(jiàn)問(wèn)題及技術(shù)支持 >  WordPress 使用 wp_redirect 函數出現 Warning: Cannot modify header information – headers already sent

WordPress 使用 wp_redirect 函數出現 Warning: Cannot modify header information – headers already sent

2017-02-27 23:11:13 15251

WordPress 使用 wp_redirect 函數出現 Warning: Cannot modify header information – headers already sent


最近更新主題的時(shí)候,使用了 wp_redirect() 函數來(lái)做一個(gè)頁(yè)面跳轉,沒(méi)想到出現了“Warning: Cannot modify header information – headers already sent”的錯誤提示:

2015-10-29_193459_wpdaxue_com

搜索了下,php中使用重定向跳轉時(shí),“Warning: Cannot modify header information – headers already sent by (output started at…”是常見(jiàn)的錯誤提醒,出現該錯誤的原因是跳轉函數前有包括回車(chē)、空格、換行的輸出,解決方法是使用ob_start()函數打開(kāi)緩沖區,使用跳轉前的輸入進(jìn)入緩沖區而不會(huì )立即輸出,避免這個(gè)錯誤提醒。

如果是 WordPress 使用 wp_redirect() 函數導致的這個(gè)問(wèn)題,在當前主題的 functions.php 文件中添加以下函數即可:

/**
* 解決 wp_redirect()導致的 Warning: Cannot modify header information 問(wèn)題
* http://www.tjdsmy.cn/wp_redirect-Cannot-modify-header-information.html
*/function cmp_do_output_buffer() {
    ob_start();}add_action('init', 'cmp_do_output_buffer');


提交成功!非常感謝您的反饋,我們會(huì )繼續努力做到更好!

這條文檔是否有幫助解決問(wèn)題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問(wèn)題:
-->