网站建设

解决WordPress Feed、RSS以及Sitemap.xml访问报错问题

Jager · 6月24日 · 2014年 · · 1223次已读

今天,查看百度站长平台的 sitemap 抓取情况时,发现提示解析错误:

解决WordPress Feed、RSS以及Sitemap.xml访问报错问题

很纳闷的点开看了下:

解决WordPress Feed、RSS以及Sitemap.xml访问报错问题

这个 sitemap_baidu_sp.xml 是 sitemap_baidu_sp.php 的伪静态,最近并没有改动过这个文件,怎么会出错呢?

于是访问https://zhang.ge/sitemap_m.xml试了下,发现如下报错:

解决WordPress Feed、RSS以及Sitemap.xml访问报错问题

 This page contains the following errors:

error on line 2 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.

XML 解析错误:xml 处理指令不在实体的开始部分

 

右键查看源代码,发现<?xml version="1.0" encoding="UTF-8"?>前面存在空行!

以为是代码变动了,调试了半天的 sitemap_baidu_sp.php 的标题头,都没能搞定!

想到同为 xml 格式,于是继续打开了https://zhang.ge/feed https://zhang.ge/sitemap.xml 发现报的是同样的错误!

无奈之下度了下错误关键字,找到了一个大神的教程:

①、和某插件冲突。

....略....

①、有关 Feed 输出的某个 php 文件后有空行。

这里的某个文件指的是 wp-feed.php,wp-atom.php,wp-rss2.php,wp-config.php 和主题文件夹下的 functions.php 文件,一般来说 wp-feed.php,wp-atom.php,wp-rss2.php,wp-config.php 这些主程序文件我们是很少动的,
所以这些文件想都不用想直接排除掉,那么问题的症结就再 function.php 文件上了。

摘自翔子

不多想,直接编辑 functions.php,发现是昨天测试一个功能时,撤掉代码后在<?php 前留下了一个空行:

解决WordPress Feed、RSS以及Sitemap.xml访问报错问题

 

删除后,立竿见影!搞定:

解决WordPress Feed、RSS以及Sitemap.xml访问报错问题

26 条回应
  1. Wings Blog 2014-6-24 · 22:16

    赞个

  2. 每日秀 2014-6-25 · 7:23

    路过

  3. 微信营销博客 2014-6-25 · 11:14

    学习了博主。

  4. 兔子酱 2014-6-25 · 12:56

    真是无折腾不成活哦

    • avatar
      Jager 2014-6-25 · 13:10

      不折腾不幸福。

  5. 夏日博客 2014-6-25 · 13:28

    插件还是尽量要少装一些。

    • avatar
      Jager 2014-6-25 · 13:40

      我想说这文章所述,和插件没有毛线关系。。。

  6. 碧海神风 2014-6-26 · 15:43

    戈戈,我好喜欢看着你折腾WP的文章,太能干了!

    • avatar
      Jager 2014-6-26 · 17:51

      • yedward 2014-6-28 · 9:08

        戈戈,我也喜欢看。

  7. 微历史 2014-6-26 · 23:36

    我昨天在你们的指点下仍然没有搞定兔子酱汉化的mobile主题,也可能跟插件有关

    • avatar
      Jager 2014-6-27 · 8:39

      有时间用我的那个方法和主题吧,不会的话把后台临时密码给我。

      • 微历史 2014-6-27 · 9:21

        好的,我需要时找你

  8. yedward 2014-6-28 · 9:07

    我眼拙,咋没看出来这个空行在function中有什么影响呢

    • avatar
      Jager 2014-6-28 · 23:10

      你可以在function顶部加一个空行保存后打开feed地址看看。

  9. xing 2014-7-2 · 16:48

    我的还是老样子,没发现空格, This page contains the following errors:error on line 1 at column 6: XML declaration allowed only at the start of the documentBelow is a rendering of the page up to the first error.

  10. 青睐麦彩 2014-8-21 · 17:41

    和你一样的情况,sitemap好使,就是feed报错,function里头删了一遍空格也没用。愁死了。

    • avatar
      Jager 2014-8-21 · 17:46

      我看你的feed不是好了么?

      • 青睐麦彩 2014-8-21 · 17:48

        哈哈,可能是缓存,多谢谢。

        • avatar
          Jager 2014-8-21 · 18:04

  11. DRIFTER 2015-9-16 · 12:57

    哎呀,终于解决问题了 ,换了好几个插件都是这个问题,我还以为哪儿有问题了呢。 谢了

  12. 45du 2016-9-9 · 22:30

    你没有发现嘛? 你的sitemap 没有样式,,,我解决了你讲的问题!

  13. 玉满斋 2017-5-9 · 8:34

    这个问题太坑爹了!我都已经中标多次了!无语!

  14. leo 2018-2-22 · 17:48

    error on line 3 at column 6: XML declaration allowed only at the start of the document

    我的是这个错误,不知怎么解决,找了好久都没有发现问题

  15. 异星软件空间 2019-2-13 · 15:40

    学习了!!

  16. 刘少技术博客 2019-5-23 · 15:41

    哎~找了半天也是找不到问题,几乎能想到的文件都查看了,但是没有找到问题所在,求大神指点