XML Site Map error – XML declaration allowed only at the start of the document

Digitization Transformation Binary  - geralt / Pixabay

I was trying to upload the XML sitemap of my website and encountered the below-mentioned error which did not let my sitemap show up.

This page contains the following errors:

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

Below is a rendering of the page up to the first error.

I was able to solve the issue and here is how I did it.

Why the error – error on line 2 at column 6: XML declaration allowed only at the start of the document – shows up when I load the XML site-map?

Although there might be various reason, in this case the most common problem is likely to be an extra line at the start of the PHP declaration. Technically PHP declaration should the first thing in every page.

How to find out if an extra space is causing the XML site-map error – XML declaration allowed only at the start of the document

This is pretty easy step. Here we we be checking if the blank line exists. And if it exists, does it exist only on the XML page or other pages as well.

Checking the XML Site-Map page

Head over to the XML page which shows the error. Now open the source page. For chrome use CTRL + U.

Do you find any blank line before the <?xml version=”1.0″ encoding=”UTF-8″?> tag?

It would look something like this:

error on line 2 at column 6: XML declaration allowed only at the start of the document - blank line above the xml declaration

The XML declaration starts from line 2 but should ideally start at line 1.

Now, we will need to check if the issue lies with just the XML site map or other pages as well.

Checking other pages for blank link before XML declaration

Go to any page of your website (it’s best to open up the homepage and any other blog page). Try the same steps as we did for the XML sitemap page. If you find the same blank link, you can be sure that this is where the issue lies.

Checking for the reason for the blank line

So since we are sure that the issue is cause by the blank line, we need to check what is causing the blank line to jump in our page. We will be selectively checking using hit-and-try method.

Checking if the plugging causes the error

Head over to the Plugin page and select all the active plugins and deactivate them. Also make sure you note down the plugins which were active.

Once deactivated, check if the error is present or not. If the error no more shows up, the issue is with the plugin.

In case this does not solve the issue check for themes.

Identifying the problematic plugin

Activate the plugins one by one and keep on checking until you identify the plugin which is causing the error.

Replace the plugin

Once you find the problematic plugin there are a few things you can do. If this is a popular plugin, there must be some posts on the plugin’s blog or website or forums. If not the next best option would be to find an alternative plugin. Incase no alternative can be found, you can try tweaking the plugins or raising a ticket.

Checking themes for the problem

If deactivating the plugins does not resolve the problem, try switching to the default wordpress theme. If this solves the problem, change your theme.

Hope that solves your problem. Incase it doesn’t, try contacting any web-developer.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top