无法修改标头信息-标头已由... WordPress问题发送 [英] Cannot modify header information - headers already sent by... WordPress Issue

查看:95
本文介绍了无法修改标头信息-标头已由... WordPress问题发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到此错误.我不知道要解决这个问题.

I'm encountering this error. and I have no idea dealing with this.

无法修改标头信息-标头已由发送(输出 开始于 /home/ben213/public_html/wp-content/themes/Bendaggers/functions.php:9) 在第934行的/home/ben213/public_html/wp-includes/pluggable.php中

Cannot modify header information - headers already sent by (output started at /home/ben213/public_html/wp-content/themes/Bendaggers/functions.php:9) in /home/ben213/public_html/wp-includes/pluggable.php on line 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;

由于我不是程序员,所以我很难解决这个问题.似乎有什么问题? 请帮我...

I'm having a hard time figuring this out since im not a programmer. what seems to be wrong? kindly help me please...

推荐答案

您的主题是将输出(文本)输出到浏览器,但是由于某些原因,WordPress会将用户(使用wp_redirect)重定向到该页面之前,而不是整个页面页面已呈现.您无法开始打印输出然后进行重定向,否则将看到错误.这就是Paul Grime在评论中所表达的.

Your theme is printing output (text) to the browser, but then for some reason WordPress is redirecting the user (with wp_redirect) away from that page before the whole page is rendered. You can't start printing output and then redirect, or you'll get the error you see. That's what Paul Grime was getting at in his comment.

肯·怀特(Ken White)提到有类似问题的帖子.我通过缓冲脚本的输出来解决此问题.

Ken White commented with a reference to a post with a similar problem. I've fixed this in my own experience by buffering the output of the script.

在主题的functions.php文件(每次加载主题页面时都会包含该文件)中,放置以下内容:

In your theme's functions.php file (which gets included every time your theme's pages load), put the following:

//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可以根据需要将用户重定向(作为其自身逻辑的一部分).

Now, even if part of your theme starts to send input to the browser, PHP won't send that text until the page is fully loaded, which allows WordPress to redirect users, if necessary, as part of its own logic.

这篇关于无法修改标头信息-标头已由... WordPress问题发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆