[英]PHP - cannot modify header information - headers already sent by (output started at
[英]Warning:Cannot modify header information-headers already sent by (output started at (/themes/kaboodle/functions/admin-setup.php
警告信息 :
警告:無法在第940行/wp-includes/pluggable.php中修改已經由發送的標題信息標題(輸出從(/themes/kaboodle/functions/admin-setup.php:174開始)
文件admin-setup.php
第174行似乎出現了警告,內容如下:
echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";
我已經檢查了php quotes()上任何隱藏的空格的admin-setup文件,但錯誤仍然存在。 誰能幫助我解決此警告消息。 供參考,我將下面的行放在檢查此類錯誤的位置。
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()
首先,您應該使用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' );
其次,應該使用admin_init
或init
上的wp_safe_redirect
進行重定向,以確保在應該進行重定向之前沒有輸出。 例如
function my_redirect()
{
wp_safe_redirect('link_here');
}
add_action('admin_init', 'my_redirect'); // for admin
add_action('init', 'my_redirect'); // for frontend
另外,重定向之前回顯樣式的意義是什么?
是的,您可以解決該錯誤的錯誤是
1.之前的空格
<?php ?>
2.html標頭之前的內容
3.標題前回顯的任何內容
你必須刪除那些
但即使在此之后,它也會向您顯示相同的錯誤,您可以像這樣使用javascript重定向
<script type="text/javascript">
window.location.assign('your desired location');
</script>
header('Location: ' . admin_url() . 'admin.php?page=woothemes');
在回聲之后,您將無法使用該功能。 echo
發送標頭(大多數服務器將其輸出分段發送),因此您無法再使用header()
命令對其進行修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.