How To Fix WordPress “error on line 3 at column 6” From sitemap.xml?

Back in 2010, a problem had arisen where WordPress would cause an error to appear in the browser whenever loading the RSS feed.

This problem simply prevented the WordPress RSS feed from working. The RSS feed was quite important to many website owners back then and it is probably still important to many even today.

As of lately, a similar error has been popping up on the sitemap.xml of WordPress websites. On a browser like Chrome, the error that you might get in your sitemap.xml while working on your WordPress website reads something like:

“This page contains the following errors: error on line 3 at column 6: XML declaration allowed only at the start of the document”

WordPress error

The sitemap will get messed up if this error appears, as a result of which an invalid XML will be produced. If you are generating the sitemap using a plugin, it may seem like the issue is a result of the plugin, but that is actually not the case. You might assume that changing your website’s theme and/or disabling plugins will resolve the issue, but that will not be necessary, so it is not worth wasting your time on that.

How To Remove WordPress “error on line 3 at column 6” From sitemap.xml?

Step #1: To get rid of this error, you will require a small PHP file/script by the name of “spacefix.php” that you can download.

Step #2: Once you have downloaded the above .php file, it will have to be uploaded into the Theme’s folder of your WordPress website. If you are not sure which is the Theme’s folder, it is basically the directory that contains a functions.php file. Make sure that you avoid uploading the mentioned downloaded .php file into the plugins or root folder; it needs to be placed in the Theme’s folder.

Step #3: Once you have uploaded the PHP file into the Theme’s folder, you will have to edit the functions.php file. You will have to add “include(“spacefix.php”);” right after the first line “<?php” in the functions.php file.

In other words, it should look like the following:

<?php
include("spacefix.php");

Make sure you do not tinker with anything else in the functions.php file unless you know what you are doing. Make sure that you uploaded the spacefix.php into the same folder where the functions.php is present, which is supposed to be the Theme’s folder. If you end up uploading the spacefix.php in some other folder, then you will have to change the file’s path, which will only be a waste of effort and time.

Conclusion

Make sure you save the functions.php after doing all of the above, after which you can refresh the sitemap.xml. The sitemap.xml will now work, along with any other XML that is generated by WordPress as well as the RSS feeds. The “error on line 3 at column 6” will no longer mess up your WordPress website’s sitemap.xml.

You may post a comment in case this solution does not work for you, but it will likely not come to that because it has been verified to resolve the mentioned issue.

20 thoughts on “How To Fix WordPress “error on line 3 at column 6” From sitemap.xml?”

  1. I have above procedure completely for fixes but didn’t get any result. I am still getting the error “error on line 3 at column 6: XML declaration allowed only at the start of the document”.

    Could anyone please help on this ?

    Reply
  2. This isn’t working for me. What do you mean by “refresh the sitemap.xml”? Is it just refresh the sitemap page in browser (which is what I did), or something else?

    Reply
  3. Hello Dear, We’ve written an article about common sitemap errors which you can find here. Solution is very easy and it will work 100%.

    Reply

Leave a Comment