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.
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.
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.
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.
Make sure your PHP file doesn’t have any space prior the PHP tag
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.
You should reverse any changes made in the theme code, just to verify if the problem is resolved.
Try deactivating plugins one by one to check if the problem still exists.
Make sure you don’t have multiple plugins for sitemap creation
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.
Sitemap creation and submission are very important if you really want your content to be index faster on Google and other search engines. A sitemap is something which tells webmasters about the links added, updated or deleted on your website.
Every time when you add a post or page, delete some content on your website or update the content, sitemap gets updated itself and search engines like Google follows sitemap timestamp to evaluate and rank your content accordingly.
We have always said that websites which are updated regularly have high chances of ranking than a non-updated site. Google also wants frequent and fruitful updation.
So, how to create a sitemap and how to submit a sitemap to Google and other search engines? is the main concern now.
Creating and submitting a sitemap
If you do not create or submit your sitemap, chances are very hard that your site will rank. If you don’t do it it will come under a big SEO mistake.
For a non-WordPress Website
When we call a non-Wordpress website. it simply means any website which are not using WordPress.com Services. It can be any html, php or other CMS like Drupal or Joomla sites. It can be a Blogger or weebly website.
So, If you want to create a sitemap for non-WordPress website then I already have published a separate article on this. Refer the article here- Read Now
By the way, this article can be used for creating a sitemap for a WordPress website as well. But I don’t recommend this way of sitemap creation and submission for WordPress.
If you want to migrate form blogger to WordPress this post will be useful for you.
So, you might be happy. You have performed an important task of blogging which is sitemap creation.
Now we will see, How we can submit this sitemap to Google, Bing and Yandex Webmaster tools?
Sitemap Submission to Webmasters
Generally sitemap submission is done for Google, Bing and Yandex Webmasters. We will see them one by one here. We have focused more on Google Sitemap Submission, you can follow up same for Bing and Yandex.
Sitemap Submission in Google Search Console
Follow the steps to submit your sitemap to Google Search Console –
1 Open Google Search Console 2. Click Start Now to create an account 3. Sign in using your Gmail 4. Enter your domain name and click on Add property
5. Verify your domain Ownership using any method. The available methods are Html file upload, Html tag, Google Analytics, Google tag manager and Domain name provider.
Html File Upload – Download and upload the given html file to the root directory i.e inside public.html folder.
HTML Tag – This method is very easy. an HTML tag will be provided to you. Simply install and activate the Insert headers and footers plugin. Once installed put the HTML tag inside the header section and click on the save button.
Google Analytics – You can do it in either way. But first, you need to add your website to Google analytics. A tracking code called gtag.js tracking code will be provided to you. Just add that code before </head> tag.
For this, you can use the Google Analytics Plugin or Insert headers and footers plugin.
These three methods are sufficient enough. Don’t go for Google tag manager or Domain name provider methods. It is a bit complicated than these.
6. Once your domain ownership is verified. Now you are ready to submit your sitemap.
7. Go to stemap section and add your sitemap link.
8. You are done with the process. Wait for Google to discover, evaluate and index your links.
Note: The process goes same for Bing and Yandex Webmaster. You can submit your sitemap there as well. If you do so, these search engines will index your site.