Fixing Common XML Sitemap Errors in WordPress
Content
If you're seeing errors like "XML declaration allowed only at the start of the document" or "Extra content at the end of the document" when trying to view your sitemap, you're not alone. These are common issues reported by users of the 'XML Sitemap Generator for Google' plugin and other sitemap generators. This guide will explain why these errors happen and provide the most effective solutions to resolve them.
Why Do These XML Sitemap Errors Occur?
These errors are almost never caused by a bug in the sitemap plugin itself. The 'XML Sitemap Generator for Google' plugin generates a virtual sitemap on the fly when it is requested. For the XML to be valid, it must be the first and only content output by WordPress. The most common root cause is unwanted whitespace or characters being sent to the browser before the plugin can output its XML code. This "extra content" corrupts the sitemap, making it unreadable by search engines and browsers.
This extraneous content typically originates from one of three places:
- Your Theme: A space or blank line in your theme's
functions.phpfile, often after the closing?>PHP tag. - Another Plugin: A conflict with another active plugin that is outputting content or buffering headers incorrectly.
- Incorrect Encoding: Content on your site (like in a post or page) that contains invalid UTF-8 characters, which can break the XML structure.
How to Troubleshoot and Fix Sitemap Errors
Solution 1: Check for Whitespace in Your Theme's functions.php File
This is the most frequent culprit. Even a single space or blank line after the closing ?> tag in your theme's functions.php file will be output to the browser, breaking the XML.
- Access your website's files via FTP or your hosting provider's file manager.
- Navigate to
/wp-content/themes/your-theme-name/. - Open the
functions.phpfile in a code editor. - Scroll to the very end of the file. If you see a
?>tag, ensure there is absolutely no whitespace (spaces, tabs, or blank lines) after it. The best practice is to omit the closing?>tag entirely to prevent this issue. - Save the file and clear your WordPress cache (if applicable). Then, reload your sitemap URL (e.g.,
yoursite.com/sitemap.xml) to see if the error is resolved.
Solution 2: Identify a Conflicting Plugin
If your theme's file is clean, the next step is to check for a plugin conflict.
- Deactivate all plugins except for 'XML Sitemap Generator for Google'.
- Check your sitemap. If it loads without errors, you know the problem was caused by a plugin.
- Reactivate your plugins one by one, checking the sitemap after activating each one.
- When the error reappears, you have found the conflicting plugin. You can then contact the author of that plugin for support or look for an alternative. Common conflicts have been reported with caching, optimization, and security plugins.
Solution 3: Check for Invalid UTF-8 Characters
Errors like "Input is not proper UTF-8" indicate that a post, page, or custom field contains special characters that are not formatted correctly. This can corrupt the sitemap during generation.
- This can be more difficult to track down. If you recently edited or published content before the error appeared, try temporarily moving that content to trash and rebuilding your sitemap.
- Some users have resolved this by increasing their PHP memory limit, as the sitemap generation can fail on large sites if it runs out of memory before completing the XML output.
Solution 4: Other Quick Checks
- Caching: If you use a caching plugin or server-level cache, purge all caches completely after making any of the changes above.
- Robots.txt: If you have switched from another sitemap plugin (like Yoast SEO), ensure your
robots.txtfile is not still pointing to an old, now non-existent sitemap URL.
Conclusion
XML sitemap errors are frustrating but are almost always solvable by systematically checking for outside interference. The problem is invariably caused by something else on your WordPress site—a theme issue, a plugin conflict, or invalid content—inserting itself into the XML output. By following the troubleshooting steps above, you can identify the cause and get your sitemap working again, ensuring search engines can properly crawl and index your site.
Related Support Threads Support
-
Error in Google consolehttps://wordpress.org/support/topic/error-in-google-console-4/
-
Missing XML tag – Google Webmaster Errorhttps://wordpress.org/support/topic/missing-xml-tag-google-webmaster-error/
-
XML Sitemap Data Locationhttps://wordpress.org/support/topic/xml-sitemap-data-location/
-
Error in xml sitemaphttps://wordpress.org/support/topic/error-in-xml-sitemap-2/
-
Sitemap can be read, but has errorshttps://wordpress.org/support/topic/sitemap-can-be-read-but-has-errors-12/
-
Missing XML taghttps://wordpress.org/support/topic/missing-xml-tag-13/
-
XSLTProsessor Error Mesasgeshttps://wordpress.org/support/topic/xsltprosessor-error-mesasges/
-
Google error Missing XML taghttps://wordpress.org/support/topic/google-error-missing-xml-tag/
-
Google Parse Errorhttps://wordpress.org/support/topic/google-parse-error/
-
error on line 1 at column 82: XML declarationhttps://wordpress.org/support/topic/error-on-line-1-at-column-82-xml-declaration-allowed-only-at-the-start-of-the-d/
-
Parsing error on sitemap-mischttps://wordpress.org/support/topic/parsing-error-on-sitemap-misc/
-
Sitemap not found – error on line 2https://wordpress.org/support/topic/sitemap-not-found-error-on-line-2/
-
DOMDocument::loadXML Errorshttps://wordpress.org/support/topic/domdocumentloadxml-errors/
-
Error when retrieving sitemapshttps://wordpress.org/support/topic/error-when-retrieving-sitemaps/
-
XML tag missing errorhttps://wordpress.org/support/topic/xml-tag-missing-error/
-
error on line 2 at column 6: XML declaration allowed only at the start of the dohttps://wordpress.org/support/topic/error-on-line-2-at-column-6-xml-declaration-allowed-only-at-the-start-of-the-do-2/
-
XML Parsing Error: XML or text declaration not at start of entity Location: httphttps://wordpress.org/support/topic/xml-parsing-error-xml-or-text-declaration-not-at-start-of-entity-location-http/
-
Missing XML taghttps://wordpress.org/support/topic/missing-xml-tag-10/
-
I have a problem in Google XML Sitemapshttps://wordpress.org/support/topic/i-have-a-problem-in-google-xml-sitemaps-2/
-
Google XML Sitemaps showing error on line 42 at column 6: XML declaration allowehttps://wordpress.org/support/topic/google-xml-sitemaps-showing-error-on-line-42-at-column-6-xml-declaration-allowe/
-
DOMDocument::loadXML(): Input is not proper UTF-8https://wordpress.org/support/topic/domdocumentloadxml-input-is-not-proper-utf-8/
-
Latest version of plugin generates an errorhttps://wordpress.org/support/topic/latest-version-of-plugin-generates-an-error/
-
sitemap.xml with XML Parsing Errorhttps://wordpress.org/support/topic/sitemap-xml-with-xml-parsing-error/
-
“Missing XML Tag” Error in Google Search Consolehttps://wordpress.org/support/topic/missing-xml-tag-error-in-google-search-console/
-
Error Messages?https://wordpress.org/support/topic/error-messages-82/
-
Sitemap.xml is working but Google says missing xml tag (fix inside)https://wordpress.org/support/topic/sitemapxml-is-working-but-google-says-missing-xml-tag-link-inside/
-
Google – Parsing errorhttps://wordpress.org/support/topic/google-parsing-error/
-
Sitemap Errorhttps://wordpress.org/support/topic/sitemap-error-51/
-
Sitemap being generated by the plugin, but does not accesshttps://wordpress.org/support/topic/sitemap-being-generated-by-the-plugin-but-does-not-access/
-
Error after first generated sitemaphttps://wordpress.org/support/topic/error-after-first-generated-sitemap/
-
Google reports “missing XML tag”https://wordpress.org/support/topic/google-reports-missing-xml-tag/
-
XML Sitemap Errorhttps://wordpress.org/support/topic/xml-sitemap-error-11/
-
XML Parsing Error: xml processing instruction not at start of external entityhttps://wordpress.org/support/topic/xml-parsing-error-xml-processing-instruction-not-at-start-of-external-entity/
-
Error with XML sitemaphttps://wordpress.org/support/topic/error-with-xml-sitemap/
-
Do not work sitemaphttps://wordpress.org/support/topic/do-not-work-sitemap/
-
XML Sitemap Generator for Google errorhttps://wordpress.org/support/topic/xml-sitemap-generator-for-google-error/
-
Error in xml tagshttps://wordpress.org/support/topic/error-in-script-2/
-
DOMDocument::loadXML(): Input is not proper UTF-8https://wordpress.org/support/topic/domdocumentloadxml-input-is-not-proper-utf-8-2/
-
Missing XML tag (google won’t validate)https://wordpress.org/support/topic/missing-xml-tag-google-wont-validate/
-
Missing XML tag on line 3https://wordpress.org/support/topic/missing-xml-tag-on-line-3/
-
Error in xml at line 1https://wordpress.org/support/topic/error-in-xml-at-line-1/
-
Error in sitemap, how to manually edit sitemap.xml?https://wordpress.org/support/topic/error-in-sitemap-how-to-manually-edit-sitemap-xml/
-
PHP Warning: DOMDocument::loadXMLhttps://wordpress.org/support/topic/php-warning-domdocumentloadxml/
-
This page contains the following errors …https://wordpress.org/support/topic/this-page-contains-the-following-errors-10/
-
Error on wordpress 4.6https://wordpress.org/support/topic/error-on-wordpress-46/
-
File has mixed line endings; this may cause incorrect resultshttps://wordpress.org/support/topic/file-has-mixed-line-endings-this-may-cause-incorrect-results/
-
Sitemap Not Workinghttps://wordpress.org/support/topic/sitemap-not-working-17/