Skip links

Fix wordpress sitemap error: error on line 2 at column 6

If you are here you have probably seen an error similar to “error on line 2 at column 6: XML declaration allowed only at the start of the document “. This typically happens when a plugin or theme function incorrectly adds an empty white-space at the beginning of the sitemap. Yoast has a pretty good documentation about the issue. Make sure to check it out here. There are few ways to fix this sitemap error. Let’s see what they are.

Manually remove the white-spaces

First you have to check if there are any white-spaces in the functions.php and wp-config.php before the <? tag and after the ending ?>. If there is any remove them and hopefully you are good to go. If not you can use the following solution.

Using a script

First log into the cpanel and navigate to your wordpress root directory using file manager. Then create a new file called whitespacefix.php and add the following content into it.

So it would looks like this.

Then open the index.php and add the line include(‘whitespacefix.php’); right after the <?php tag

And you are done. Sitemap should be working now.

Content retrieved from:

Leave a comment

This website uses cookies to improve your web experience.
Subscribe To Newsletter
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Give it a try, you can unsubscribe anytime.