Just revamped. Got feedback? Share now.

Privacy
Subscribe

Fixed Error: WordPress XML Declaration Allowed Only Start of Document

By Aqsa Jamil Published 7 Nov, 2022 Modified yesterday Viewed 100 times Read in 2m 10s
Experience Based
Content Validity: Valid and Applicable Comprehension: Level 2 – For Professionals

Is your sitemap or other XML file in Wordpress throwing XML declaration error? It's not WP error. Something happened on our files end. Lets get into that.

You may have encountered an error like below:

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.

We encountered this error on WP Sitemap /wp-sitemap.xml and SEO Yoast Sitemap XML /sitemap_index.xml URLs. However, in you case it could be other website with or without WP or Yoast.

This XML declaration error appears for any of the following reasons: –

  • You have an empty or blank line at the end of any PHP file in wordpress plugins or themes or your other non-WP site. This is the most common issue.
  • You are using a plugin or script that is altering XML headers.

How to Fix Empty Line at End of File Issue in WP

Though this issue is most common issue, however, this is sometimes frustrating to fix. Since it is hard to track which file could be having an empty line at the end of file, it becomes a time taking activity.

The helping news is: you can still fix this with divide and conquer rule.

Start with most common files where you or your team edit code. These are functions.php in child or parent theme, wp-config.php in the WP root directory, and template files (if you have) in child theme.

If you don’t make changes to wp-config.php or functions.php or other template files often, then head towards ‘recently’ installed plugins. Disable them one by one and check if the XML declaration error goes away.

Common plugins that may produce this error are: –

  • Plugins related to webp or other image format generation (common)
  • Plugins related to caching that modify headers

If you just installed so many plugins or it was your new WP installation with tons of plugins and themes, we recommend using Health Check and Troubleshooting Plugin. This works by disabling extension and themes one by one without affecting your visitors. This is really helpful for custom-built websites since disabling some extensions throw fatal errors most of the time.

Related similar errors which the above solution may fix:

  • 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.
  • error on line 1 at column 7: xml declaration allowed only at the start of the document
  • xml declaration allowed only at the start of the document wordpress
  • yoast error on line 2 at column 6: xml declaration allowed only at the start of the document

×

Your feedback matters.

Our standardized editorial process ensures right, timely, and healthy updates to our content. Your honest opinion drives significant improvement to our content. We appreciate you are taking time to share that.

×