WP网站地图XML报错This page contains the following errors:

今天突然发现网站地图https://www.123how.com/sitemap.xml生成出错,报错内容:

This page contains the following errors: error on line 3 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.

SiteMap网站地图生成出错原因#

我这边出现问题应该是插件冲突导致的
买了一个seo插件,功能挺多,但是bug也多
等发现问题后,已经不知道怎么恢复回来了,那只能找其他办法解决

网上比较多的是funtions.php文件<?php前有空行,这种一般是认为,好解决
针对我这种插件引起的排查就麻烦,不知道是哪个文件出了问题

解决办法:#

既然不知道问题出在哪个文件,那就从程序末端做处理
查看网站地图源码的时候看到第一行是空行,只要去掉空行就能解决问题

在网站根目录(比如我根目录是:www.123how.com/),新建文件spacefix.php
代码内容:

Copy
<?php function ___wejns_wp_whitespace_fix($input) { $allowed = false; $found = false; foreach (headers_list() as $header) { if (preg_match("/^content-type:\\s+(text\\/|application\\/((xhtml|atom|rss)\\+xml|xml))/i", $header)) { $allowed = true; } if (preg_match("/^content-type:\\s+/i", $header)) { $found = true; } } if ($allowed || !$found) { return preg_replace("/\\A\\s*/m", "", $input); } else { return $input; } } ob_start("___wejns_wp_whitespace_fix"); ?>

然后在主题目录下找到functions.php,在开头的<?php后面插入include("spacefix.php");
把上面新建的spacefix.php文件引入进来
如图所示:

最后记得清理缓存,就能看到网站地图可以正常生成了,作用就是去除空行。

posted @   "无问西东"  阅读(204)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验
网络创业项目 123how出海导航
点击右上角即可分享
微信分享提示
CONTENTS