【问题标题】:Warning: Cannot modify header information - Wordpress警告:无法修改标题信息 - Wordpress
【发布时间】:2020-07-28 01:33:35
【问题描述】:

我做了一些研究来解决这个问题,但似乎对我不起作用,我检查了所有间距,替换了原始 functions.php,仔细检查 wp-config.php 但仍然不适合我。我使用 wordpress 5.4 版本,安装 Elementor Pro 并插入 WP-Filebase 短代码后,出现错误消息。

警告:无法修改标头信息 - 标头已由 /home 中的(输出开始于 /home/customer/www/xxx.xxx/public_html/xxx/wp-includes/class.wp-scripts.php:405)发送/customer/www/xxx.xxx/public_html/xxx/wp-admin/admin-header.php 在第 9 行>

这是第 405 行的 class.wp-scripts.php

* Filters the HTML script tag of an enqueued script.
*
* @since 4.1.0
*
* @param string $tag    The `<script>` tag for the enqueued script.
* @param string $handle The script's registered handle.
* @param string $src    The script's source URL.
*/
$tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );

if ( $this->do_concat ) {
        $this->print_html .= $tag;
    } else {
        echo $tag;
    }

    return true;
}

这是第 9 行的 admin-header.php

header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
if ( ! defined( 'WP_ADMIN' ) ) {
    require_once __DIR__ . '/admin.php';
}

【问题讨论】:

  • 这是do_item() 函数的一部分,它“处理脚本依赖。”。看起来您的 admin-header.php 脚本运行得太晚,无法发送 header() 命令
  • 使用 ob_start();在标题之前或之后
  • 你想在那里实现什么?为什么此时需要切换到不同的字符编码?
  • @Ravi 插入 ob_start();我的页面变成了空白页面,它应该显示 elementor pro 编辑器页面,这是截图 (khookeiwai.work/error.jpg)
  • @CBroe 我正在尝试将 WP-Filebase 短代码插入到 elementor pro 编辑器中,但是在我插入它之后,出现了错误消息。当我停用 WP-Filebase 插件时,一切正常。我不确定切换到不同的字符编码意味着什么..

标签: php wordpress shortcode elementor


【解决方案1】:

肮脏廉价的解决方案,在标题部分添加@。

@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );

【讨论】:

  • 谢谢Pedro,错误信息消失了,现在变成空白页了,应该是elementor pro editor page..
  • 检查你的错误日志,那里应该有一些有意义的信息。
  • 感谢 Pedro,这是我的网站控制台 (khookeiwai.work/error.jpg)。如果您能给我一些指导或方向,将不胜感激..
  • 更新:应该是这个(khookeiwai.work/error2.jpg)
  • 您使用任何缓存管理器吗?如果是这样,请清除 wordpress 中的所有缓存,然后重试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多