Sitemap Error: XML declaration allowed only at the start of the document
I recently started a new blog called Money Bitcoin where I share my views and general information about Bitcoin, blockchain and other cryptocurrencies. However, my sitemap was pending for over a week after i submitted it to the Google search console. I tried viewing the sitemap myself and I discovered this error ” This page contains the following errors: error on line 4 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.” as displayed in the image below.
Here is how to fix this sitemap error
If you’re getting this error, it occurs when a PHP file is incorrectly outputting a PHP ?> tag, followed by some extra lines.This can be caused by:
To determine the plugin responsible for this take the following steps:
- Back up your website using Updraftplus or any other back up plugin you have installed on your WordPress
- Deactivate all plugins except the plugin that generates your sitemap
- Clear your browser cache and check if the problem has been fixed.
- If the problem has been fixed then you know it was caused by one of the plugins you deactivated. Reactivate each plugin one at a time until the problem occurs. This will help you identify the plugin responsible.
- Switch to the default WordPress theme (currently Twenty Seven).
- If the problem is fixed then you know it was caused by your theme.
None of the steps listed above solved the sitemap issue. Then I remembered editing my wp-config.php on 2 occasions. The first was when I wanted to fix the W3 Total cache error where it couldn’t write to my wp-config.php and the second time was when I was configuring my SSL Certificate.
- I simply opened my wp-config.php file and there it was, 4 empty lines before the opening “<?php”. I simply deleted the blank lines, save the changes made to wp-config.php, restarted Apache, refreshed the tab and my sitemap problem was fixed.
If you are unable to solve this error using the methods highlighted above, leave a comment and lets figure out how to fix your sitemap issue together.