Today we will talk about WordPress’s most common error in the sitemap. Generally when you open yoursite.com/sitemap.xml then you can your sitemap here. But sometimes it shows an error, today we talk about “XML declaration allowed only at the start of the document” error. When you open your sitemap using “yoursite.com/sitemap.xml” then it says –
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
Not everyone faces this problem mostly they face this problem who are using a child theme and they used to edit their child theme many times. This error is not a big error it’s so simple error and its reason is some code error in “function.php. So let’s know how to fix this error.
How To Fix Sitemap XML Declaration Error in WordPress.
 First open your WordPress dashboard.
 Go to the Appearance > theme editor > your child theme.
 Now in your child theme editor select function.php.
 here check any extra space which is available in the starting of the code or after the end of the code ?> .
 if there is any extra space remove the space and save your child theme, this error will be fixed.
This error is caused by extra spaces on the starting or after the coding. After removing the extra space everything will be fixed. Space inside the PHP doesn’t affect it so you don’t have to do anything to them.
Sometimes this error is caused by the main theme’s function.php file so if your error isn’t fixed or you didn’t find any space then you should check your main theme’s function.php file. if there is any space in the starting line or after the end of the code then remove that space.