WordPress Sitemap or RSS Feed – error on line 2 at column 6: XML declaration allowed only at the start of the document
You are trying to create and submit a sitemap for your WordPress website probably using a plugin or your WordPress RSS feed has stopped working for some reason you get this error:
WordPress error on line 2 at column 6: XML declaration allowed only at the start of the document
This feed does not validate.
line 1, column 1: Blank line before XML declaration [help]
There’s a simple quick solution but you’ll need access to website’s backend and root folder.
1) Download the following file: https://wejn.org/stuff/wejnswpwhitespacefix.php
It has no virus, you can open it with notepad or any text editor and check.
2) After downloading, upload the .PHP file into your WordPress site ROOT directory. This is wherever the wp-config.php file is. Do not upload it into the themes folder, or the plugins folder.
If you don’t trust you know where this is, it’s ok. Leave a comment and I’ll help you.
3) EDIT your index.php file and add the following right after the first line:
So at the end, your index.php should look something like this:
Some times you may have a different url from the one above so you must add it to the “include(“wejnswpwhitespacefix.php”); ” such as in the example below:
You realize that the url is always in your file before the “./wp” in the “require” line meaning the site url here is, “'”
That’s of course a condensed version of the index.php file and yours’ will probably have lots of comments and stuff in it. But the important thing is to add the include code right at the top and save. After that reload the feed page and/or your sitemap usually “https://yoursite.com/sitemap.xml/” and it’ll work!
It did for us!
Reach out in the comments if this worked for you or if you know of any other better solutions!
Lawk is a mozillian, director at Innovware and consults part time for Every1Mobile.
He loves open source, the open web, writing, reading and developing literacy tools that can teach the youth around the world especially in East Africa.