2015-09-04 27 views
0

警告消息:警告:不能修改已經發出頭信息報頭(輸出開始(/themes/kaboodle/functions/admin-setup.php

警告:不能更改頭信息 - 頭已經發出(輸出開始(/themes/kaboodle/functions/admin-setup.php:174)在/wp-includes/pluggable.php線940

有似乎在警告文件admin-setup.php的行號174,寫入如下:

echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n"; 

我檢查了php引號()上的任何隱藏空白的管理員設置文件,但仍然存在錯誤。 任何人都可以幫我解決這個警告信息。 供參考,我把行低於這些都需要檢查這樣的錯誤。

174線:

*echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";* 

再直接函數寫爲:

function woo_themeoptions_redirect() { 
    // Do redirect 
    header('Location: ' . admin_url() . 'admin.php?page=woothemes'); 
} // End woo_themeoptions_redirect() 
+0

**需要知道如果我可以通過更改用Echo **寫入的語句來解決。我試圖引用下面的鏈接* http:// stackoverflow的print/echo部分。com/questions/8028957/how-to-fix-headers-already-sent-error-in-php *但無法在我的緩存中解決同樣的問題 – user3655188

+1

輸出=>回顯內容後無法使用'header'功能 –

+0

您是否嘗試包含CSS鏈接,然後重定向頁面?如果是這樣,爲什麼?但無論如何,你可以呼應元重定向而不是使用標題。 – Popnoodles

回答

0

是的,你可以解決它

之前

1.spaces錯誤中的錯誤

01頭前

2.HTML內容

3.anything頭之前呼應

你必須刪除這些

但即使它告訴你,你可以用相同的錯誤這樣的javascript重定向

<script type="text/javascript"> 
    window.location.assign('your desired location'); 
</script> 
+0

可能是許多解決方案中的一個解決方案 –

0
header('Location: ' . admin_url() . 'admin.php?page=woothemes'); 

當你迴應任何東西后,你不能使用它。 echo發送標題(因爲大多數服務器都會將其輸出分段發送),因此您無法使用header()命令對其進行修改。

1

首先,你應該使用wp_enqueue_style添加的樣式,像這樣

function my_styles_function() 
{ 
    wp_enqueue_style('my-style-name', get_template_directory_uri() . 'somestyle.css"); 
} 

add_action('wp_enqueue_scripts', 'my_styles_function'); 

其次,重定向應該wp_safe_redirect上做admin_initinit,以確保沒有輸出重定向之前應該發生。例如

function my_redirect() 
{ 
     wp_safe_redirect('link_here'); 
} 

add_action('admin_init', 'my_redirect'); // for admin 
add_action('init', 'my_redirect'); // for frontend 

另外,重定向之前的回顯樣式的要點是什麼?

相關問題