使用WordPress站点地图插件创建站点地图时,发现访问sitamap.xml时报错了,错误提示“error on line 3 at column 6: XML declaration allowed only at the start of the document”(仅在文档开始处允许XML声明)。
处理方法
使用FTP软件获取网站根目录下wp-blog-header.php,使用如下代码替换:
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;ob_start();
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
// Set up the WordPress query.
wp();ob_end_clean();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
需要注意的是ob_start();要和$wp_did_header=true;写在同一行。ob_end_clean();要和wp();写在同一行。
原文地址:https://www.sameen.art/wordpress/wordpress-sitemap-error-solution.html





![图片[1]-WordPress网站打开又慢又卡?教你数据库优化加速图文教程-猎富团](https://www.keyuqi.com/wp-content/uploads/2023/04/8e1f57ed80e5.jpg)