Unbeknownst to me, I had a broken sitemap XML file. I was checking my Google Search Console for crawl errors related to a redirect I had set up when I discovered that my sitemap XML file was no longer functional. As I’m sure you’re aware, a good sitemap file is critical for your blog or website to be properly indexed by Google, Bing, Yahoo or any other search engine. So imagine my panic. Without a sitemap file, traffic to a site can easily decrease to a trickle of what it was. That’s why I dropped everything to “fix the XML Sitemap Error – error on line 2 at column 6” once I discovered it. While frustrating, it ended up being relatively easy to address once I understood what the error meant.
So if you’re not able to generate the XML Sitemap, do you get an error that looks like this?
If you right click the page and view page source you’ll notice that the first line is blank. The error message states that the first line must be the declaration line which shows as the second line of my XML file. That’s not good but at least the problem was a bit clearer. Another way to see the error and issue is to open an incognito window in Chrome or a “private window” in Firefox. I’ve shown screenshots of the Firefox private window when my sitemap was unaccessible. You can clearly see that the first line is blank instead of being the XML declaration needed for the sitemap to work.
Since WordPress websites can be created with any unlimited combination of themes and plugins, the conflicts that can occur are normally the first thing to examine.
However, there are a couple of other culprits that may be sabotaging the sitemap file.
The one that plagued my site was in my functions.php which had an extra >? . After removing that the sitemap instantly worked.
So, what should you look at? There are at a minimum 3 problem areas to consider.
1- Look at the .php files used by your site that you may have modified or that a plugin could modify. These include files like the wp-config.php, functions.php or any rss feeder files like wp-rss.php, wp-rss2.php or wp-atom.php. Check for any blank lines beyond the <? or ?> brackets.
2- PHP files use the <? and ?> to bracket the instructions within PHP code. An extra or missing bracket can create unwanted results including adding a blank line. In most cases, the ?> bracket is not needed in PHP code modules but may be optional in other PHP files. That was my issue with my functions.php file. Once I removed it, the unwanted white space disappeared within my sitemap.xml and it worked again.
3- Check each plugin you have starting with the most recently added to determine if any conflicts may have created the error. While the first two solutions may be closer to solving your issue, plugin conflicts do occur and can result in some weird behavior at times. So disabling and testing plugins one at a time may help you when other possibilities have been eliminated. Simply disable each plugin and then test to see if the sitemap file is functional.
If you need to test your plugins for conflicts a good free one I use is Health Check Plugin located in the WordPress.org repository. I demonstrate it in my article “Troubleshooting WordPress Plugin Conflicts Using Health Check”.
Want more tips and techniques? Check out my other articles here:
If you loved this post consider sharing it. Thanks!