Error on line 7 at column 6: XML declaration allowed only at the start of the document

sitemap error

If you run WP website and installed whatever plugin which should make sitemap.xml for WP (Yoast, All in one SEO, Google sitemaps, …) sometimes you might bump on this error message when trying to open and see your sitemap:

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

You might loose much time searching for incorrect php file in your theme, plugins or core WP files.

But here is a quick solution I found on Wejn.org

Make new PHP file with this as a content:

[xyz-ips snippet=”Spacefix”]

Name it spacefix.php

Upload it to WP top level directory.

Then, paste this into main WP index.php file at start of the file:

[xyz-ips snippet=”Spacefix-for-index”]

Try to open sitemap now. It should work as a charm.

Author: Michal “Wejn” Jirků

License: MIT