2011-09-11 135 views
32

我遇到此錯誤。我不知道如何處理這個問題。無法修改標題信息 - 標題已發送... Wordpress問題

不能更改頭信息 - 頭已經(輸出 開始在 /home/ben213/public_html/wp-content/themes/Bendaggers/functions.php:9) 發送到/ home/ben213 /的public_html /wp-includes/pluggable.php上線934

我functions.php文件行#9:

<?php if(function_exists('register_sidebar'))register_sidebar();?> 

而我pluggable.php#934

function wp_redirect($location, $status = 302) { 
    global $is_IIS; 

    $location = apply_filters('wp_redirect', $location, $status); 
    $status = apply_filters('wp_redirect_status', $status, $location); 

    if (!$location) // allows the wp_redirect filter to cancel a redirect 
     return false; 

    $location = wp_sanitize_redirect($location); 

    if (!$is_IIS && php_sapi_name() != 'cgi-fcgi') 
     status_header($status); // This causes problems on IIS and some FastCGI setups 

    header("Location: $location", true, $status);} 
endif; 
我有一個硬的時間,因爲我不是一個程序員搞清楚了這一點

。什麼似乎是錯的? 好心幫我請...

+0

嗨保羅,美好的一天!對不起,請問您能用英文翻譯一下嗎?所以我該怎麼做? –

+0

什麼是'pluggable.php'?你爲什麼擁有它?它看起來應該包含在'functions.php'之前,因爲它試圖設置HTTP標頭,並且在開始輸出HTML之前需要設置它們。 –

+0

在這裏不知道保羅,我知道的是<?php if(function_exists('register_sidebar'))register_sidebar();?>是用於widgetizing我的側邊欄。不知道,對不起。 –

回答

77

你的主題是打印輸出(文本)的瀏覽器,但後來由於某種原因,WordPress是將用戶重定向(與wp_redirect)從該網頁離開整個頁面呈現之前。你不能開始打印輸出然後重定向,否則你會看到你看到的錯誤。這就是保羅格里姆在評論中所說的。

Ken White評論了對具有類似問題的帖子的引用。我通過緩衝腳本的輸出來解決這個問題。

在你的主題functions.php文件(該文件被列入每一個你的主題的網頁加載時間),把下面的:

//allow redirection, even if my theme starts to send output to the browser 
add_action('init', 'do_output_buffer'); 
function do_output_buffer() { 
     ob_start(); 
} 

現在,即使你的主題的一部分,開始輸入發送到瀏覽器,PHP贏得在頁面完全加載之前,不會發送該文本,這使WordPress可以根據需要重定向用戶,作爲其自身邏輯的一部分。

+1

謝謝。這解決了我的問題! – Phaedrus

+1

完美的作品! – Julien

+1

@BenDaggers請將此答案標記爲正確,或對其原因進行評論。謝謝。 – hitautodestruct

18

如果您嘗試將您的當前頁面中的另一個頁面重定向到您已施加條件或無條件的地方,請使用此代碼。 E.gs你有兩頁A.php,& B.php和currenty你在A.php你想要去其他頁面B.php點擊按鈕。

if(isset($_POST['save_btn'])) 
    { 
     //write some of your code here, if necessary 
     echo'<script> window.location="B.php"; </script> '; 
    } 
相關問題