Fix XML declaration allowed only at the start of the document Sitemap Error

Search Engine Optimization

Fix XML declaration allowed only at the start of the document Sitemap Error

Have you ever seen the Sitemap error “XML declaration allowed only at the start of the document?” The day before yesterday I was trying to check my sitemap which is created by Yoast SEO plugin. I found that the sitemap is missing and a sitemap error is coming quoted XML declaration allowed only at the start of the document.

Now the question comes is why this error is coming and how can we solve that? You very well know the importance of sitemap for a site. A sitemap is like a table of contents for Search Engine like Google.

A website sitemap tells a search engine about the latest changes and modifications performed on a website web pages. You can read about the process of creating a sitemap and importance of sitemap here.

How to create a Sitemap for a WordPress Website with pictures?

How to create an XML sitemap for a non-WordPress website?

From SEO perspective also a sitemap is very important. So, always keep your sitemap updated and free from any errors. To get better results and ranking in SERPs you have to submit your sitemap to Google Search console. If you do so, Google will discover, crawl and index your site.

Read AlsoGoogle Fast indexing

Now let’s focus on solving the sitemap error “XML declaration allowed only at the start of the document.”

Why this “XML declaration allowed only at the start of the document” occurs?

There can be a lot of reasons but the main reason is unstructured data in the main code of the WordPress theme. Do you know why I have got the error? As I was editing the functions.php file and while edition I have misplaced some of the tags.

Generally, it is unwanted use of spaces in between the tags. The sitemap error “XML declaration allowed only at the start of the document” will look like this.

XML declaration allowed only at the start of the document
XML declaration allowed only at the start of the document error

So, now the question appears how this sitemap error can be fixed? Let’s have a look at this.

Fixing “XML declaration allowed only at the start of the document”

There are few things which you have to kept in mind. it will help you to fix this Sitemap problem easily.

  1. Make sure your PHP file doesn’t have any space prior the PHP tag
  2. If your website is new then you should reinstall your theme
  3. If your website is old then try replacing your core files code on by one. You can also check the code different from the main theme.
  4. You should reverse any changes made in the theme code, just to verify if the problem is resolved.
  5. Try deactivating plugins one by one to check if the problem still exists.
  6. Make sure you don’t have multiple plugins for sitemap creation
  7. Don’t add any extra declaration which is not required

I hope if you follow this then the problem “XML declaration allowed only at the start of the document” will be fixed. As I have experienced this error mostly comes due to extra spaces before the PHP tag. So keep this in mind.

If you are not able to solve this problem then comment below or contact us. We will try to help you personally.

Thanks for reading this article.

Have a good day!

Read NextGooglebot optimization for better SEO | A level up SEO tactics

Comment (1)

  1. Shashank Jain

    Hi Ravi, thank for solving my error. In my case also it was an extra space before the PHP tag which has created the “XML declaration allowed only at the start of the document” issue. Appreciated.

Comments are closed.