[英]Warning:Cannot modify header information-headers already sent by (output started at (/themes/kaboodle/functions/admin-setup.php
Warning Message : 警告信息 :
Warning:Cannot modify header information-headers already sent by (output started at (/themes/kaboodle/functions/admin-setup.php:174) in /wp-includes/pluggable.php on line 940
警告:无法在第940行/wp-includes/pluggable.php中修改已经由发送的标题信息标题(输出从(/themes/kaboodle/functions/admin-setup.php:174开始)
There is seems to an warning in line number 174 of file admin-setup.php
which is written as below : 文件
admin-setup.php
第174行似乎出现了警告,内容如下:
echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";
i have checked the admin-setup file with any hidden whitespace on php quotes() but still error is persisting. 我已经检查了php quotes()上任何隐藏的空格的admin-setup文件,但错误仍然存在。 Could anyone help me out to solve this warning message.
谁能帮助我解决此警告消息。 for reference i am putting lines below those are required to check for such error.
供参考,我将下面的行放在检查此类错误的位置。
Line 174 : 174行:
*echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";*
Re-direct function written as: 重定向功能写为:
function woo_themeoptions_redirect () {
// Do redirect
header('Location: ' . admin_url() . 'admin.php?page=woothemes');
} // End woo_themeoptions_redirect()
First, you should use wp_enqueue_style
to add styles, like so 首先,您应该使用
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' );
Second, redirects should be done with wp_safe_redirect
on admin_init
or init
to ensure there is no output before redirect is supposed to happen. 其次,应该使用
admin_init
或init
上的wp_safe_redirect
进行重定向,以确保在应该进行重定向之前没有输出。 For example 例如
function my_redirect()
{
wp_safe_redirect('link_here');
}
add_action('admin_init', 'my_redirect'); // for admin
add_action('init', 'my_redirect'); // for frontend
Also, what is the point of echoing style before redirecting? 另外,重定向之前回显样式的意义是什么?
yes you can solve it the mistakes to that error are 是的,您可以解决该错误的错误是
1.spaces before
1.之前的空格
<?php ?>
2.html contents before header
2.html标头之前的内容
3.anything echoed before header
3.标题前回显的任何内容
you have to remove those 你必须删除那些
but even after that it show you the same error you can use javascript redirect like this 但即使在此之后,它也会向您显示相同的错误,您可以像这样使用javascript重定向
<script type="text/javascript">
window.location.assign('your desired location');
</script>
header('Location: ' . admin_url() . 'admin.php?page=woothemes');
you can not use that, after you echoed anything. 在回声之后,您将无法使用该功能。 The
echo
sends the header (as most servers send their output in pieces) and therfore you can't modify it anymore with a header()
command. echo
发送标头(大多数服务器将其输出分段发送),因此您无法再使用header()
命令对其进行修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.