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

查看:52
本文介绍了无法修改标头信息 - 标头已由... 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)在/home/ben213/public_html/wp-includes/pluggable.php 第 934 行

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天全站免登陆