The error ‘XML declaration allowed only at the start of the document’

The error message “XML declaration allowed only at the start of the document” occurs when an XML declaration is found in the middle of an XML document. An XML declaration should only appear at the very beginning of an XML document, before any other content.

To fix this error, you need to ensure that the XML declaration appears only at the beginning of the document. You can do this by checking the source code of your XML document and removing any content that appears before the XML declaration. Alternatively, you can move the XML declaration to the very beginning of the document.

Here’s an example of what a correct XML declaration looks like:

xml
<?xml version="1.0" encoding="UTF-8"?>

Make sure that this declaration is the very first line of your XML document, with no other content appearing before it. If you have any other content before this declaration, remove it and try again.

If you’re encountering the “XML declaration allowed only at the start of the document” error in WordPress, it’s likely that there’s a problem with one of your WordPress files, such as the functions.php file, the wp-config.php file, or the theme’s header.php file.

To fix this error in your WordPress sitemap, follow these steps:

  1. Log in to your WordPress dashboard.
  2. Go to the “Plugins” section and deactivate any XML sitemap plugins you have installed.
  3. Check your theme’s header.php file for any spaces, blank lines, or HTML code before the “<?xml” opening tag. You can find this file by navigating to Appearance > Theme Editor in the WordPress dashboard.
  4. If you find any of these issues, remove them and save the file.
  5. Clear your browser cache and reload your sitemap.

If you’re still encountering the error after following these steps, you can also try reinstalling WordPress or contacting your hosting provider for assistance.

Leave a Reply