起因
日常查看站点,发现站点地图出现了报错,刚开始以为是插件的事情。因为我之前使用的站点地图是使用插件生成的,后来是转为使用wordpress自带的xml站点地图。排除了插件错误,那就是本身的源代码出现了问题。
原因
![图片[1]-WordPress站点地图报错:error on line 4 at column 6: XML declaration allowed only at the start of the document](https://img.huran.xyz/2022/04/06/GAFIetg1.png)
造成这种报错的一般都是XML解析错误,我们查看网页源代码,发现前面空出了三行
![图片[2]-WordPress站点地图报错:error on line 4 at column 6: XML declaration allowed only at the start of the document](https://img.huran.xyz/2022/04/06/7TDqOvpY.png)
当我们的网站代码中有空格时,将出现此错误。或导致网站无法创建站点地图的不必要的空格。
修复
前往站点根目录 –> 创建xmlerror.php
–> 粘贴下方代码 –> 保存
前往站点根目录 –> 修改index.php
–> 引入xmlerror.php
include("xmlerror.php");
![图片[3]-WordPress站点地图报错:error on line 4 at column 6: XML declaration allowed only at the start of the document](https://img.huran.xyz/2022/04/06/WzA57YUm.png)
再次查看站点地图,恢复正常
![图片[4]-WordPress站点地图报错:error on line 4 at column 6: XML declaration allowed only at the start of the document](https://img.huran.xyz/2022/04/06/vQ1TfUkW.png)

Invitation
HuRan
854262623
created:04/03/2022
Welcome to Candyhome
Use this card to join the candyhome and participate in a pleasant discussion together .
Welcome to Knlde's candyhome,wish you a nice day .
© 版权声明
THE END
喜欢就支持一下吧
请登录后发表评论
注册
社交帐号登录