无法修改标头信息-标头已由…WordPress问题发送
我遇到这个错误。而且我不知道如何处理。
无法修改标头信息-已发送的标头(输出从/home/ben213/public_html/wp- includes/pluggable.php上的/home/ben213/public_html/wp- content/themes/Bendaggers/functions.php:9开始) 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;
因为我不是程序员,所以我很难解决这个问题。怎么了?请帮助我…
-
您的主题是将输出(文本)输出到浏览器,但是由于某种原因,WordPress会在呈现整个页面之前将用户(使用wp_redirect)重定向到该页面。您无法开始打印输出然后进行重定向,否则将看到错误。保罗·格莱姆(Paul
Grime)在评论中就是这样。肯·怀特(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可以根据需要将用户重定向(作为其自身逻辑的一部分)。