Back to Community

Fixing Common XML Sitemap Errors in WordPress

47 threads Sep 16, 2025 PluginXml sitemap generator for google

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:

  1. Your Theme: A space or blank line in your theme's functions.php file, often after the closing ?> PHP tag.
  2. Another Plugin: A conflict with another active plugin that is outputting content or buffering headers incorrectly.
  3. 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.

  1. Access your website's files via FTP or your hosting provider's file manager.
  2. Navigate to /wp-content/themes/your-theme-name/.
  3. Open the functions.php file in a code editor.
  4. 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.
  5. 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.

  1. Deactivate all plugins except for 'XML Sitemap Generator for Google'.
  2. Check your sitemap. If it loads without errors, you know the problem was caused by a plugin.
  3. Reactivate your plugins one by one, checking the sitemap after activating each one.
  4. 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.txt file 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