XML 解析错误:XML 或文本声明不在实体的开头位置

缘由

自己最近搭建了一个【历史上的今天】,但想查看sitemap时发现有错误存在,错误如下图所示,后来找了一圈办法都说的关键点,但就是模糊解决办法,或者看不懂,自己去Wordpress官方找到了解决办法!

file

解决办法

原文如下

We checked on your site’s sitemap and do see the page is generating an error of ‘XML declaration allowed only at the start of the document.’ We reviewed the source code of the page and found that the document does contain a whitespace for the first line of the file, which is what is causing the issue.

The error ‘XML declaration allowed only at the start of the document’ is most often caused when another plugin or theme adds white space to the beginning of the sitemap file. You will need to view the source code of the sitemap_index.xml document in order to confirm this and we have additional information on this and how to resolve this error at the following link: https://kb.yoast.com/kb/xml-sitemap-error/

However, this issue can also be caused by an empty line at the end of your theme’s functions.php file. If there is no empty line in this file, we highly recommend running a conflict check to identify what outputs the empty white space.

In order to resolve this, we would first recommend clearing your site’s caching. If you are not sure how to clear your server caching, please speak with your host provider. Does clearing your caching from your caching plugin (W3TC, WP Supercache, etc), server (Varnish, LiteSpeed, or others), or CDN (such as Cloudflare, Amazon AWS, etc) resolve the issue?

If after clearing your site’s cache you are still experiencing the error on the sitemap, we would then recommend performing a conflict check. You can sometimes experience functionality problems or unexpected behavior from the plugin due to plugin or theme conflicts. Can you confirm you have performed a complete plugin/theme conflict check by disabling other plugins, and resetting the theme to a default such as twentyseventeen? We have additional information on how to check for a conflict here: https://kb.yoast.com/kb/how-to-check-for-plugin-conflicts/

get到的点

  • 多数的错误来之插件和主题中的空白符号插进了sitemap的页面第一行,即打开网页会发现第一行为空白的;
  • functions.php文件最后有了多余的空行;
  • 解决这个问题时缓存应该首先禁止;

我最终解决成功的步骤

  • 禁用了缓存插件;
  • 发现functions.php最后面确实多了两行空格,删除了;
  • 自己先尝试过把其他文件中的空格删除以,禁用各种插件以及修改编码格式等等都以失败告终!

综上所述,我们禁用插件后应该首先排查functions.php最后(即 ?>之后)是否有多余的空行,如果还是不行则尝试其他方法,还不行的话就不清楚了!自己可以仔细阅读原文去思考修改!说句实话,有时候感觉这些东西还是英文版的资料更全更详细!我自己百度、bing搜了一圈都没解决!

参考


要不赞赏一下?

微信
支付宝
PayPal
Bitcoin

版权声明 | Copyright

除非特别说明,本博客所有作品均采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。转载请注明转自-
https://www.emperinter.info/2020/05/21/sitemap-error-xml-declaration-allowed-only-at-the-start-of-the-document/

No comments yet.

Write a comment: