How to fix the Yoast SEO XML sitemap error

Are you getting this error when viewing the XML sitemap you created using Yoast’s excellent SEO plugin on WordPress?

yoast xml sitemap problem

I had a client with the same issue but digging around I found a few solutions which you can try as provided by feedvalidator.org:

Explanation

If an XML declaration () appears in your feed, it must be the first thing in the feed, before any whitespace.

Unfortunately, with WordPress it seems all too easy for a plugin, a theme, or for your configuration file to contain a blank line. Further compounding this problem, some — but not all — feed readers compensate for this common error, allowing the error to go undetected for quite a while.

Solution

  1. PHP also uses a similar notation: . Note that the final php ?> should be omitted from all PHP code files—modules, includes, etc. The closing delimiter is optional in PHP (but not in XML), and removing it helps prevent unwanted white space at the end of files which can cause problems with your feeds.
  2. Check your wp-rss2.php and wp-atom.php files for blank lines outside of <? and ?> bracketed sections.
  3. Check your wp-config.php file for blank lines outside of <? and ?> bracketed sections.
  4. Check your theme’s functions.php file for blank lines outside of <? and ?> bracketed sections.
  5. One by one, disable plugins and revalidate until you isolate the one causing the problem.

For my client, solution 4 resolved the problem. By removing the one line of blank space in the functions.php file, the XML feed worked again.

fix yoast seo xml sitemap

← Previous post

Next post →

4 Comments

  1. josip

    Thanks a lot. This is the weirdest error what I every saw!

    • dja360

      Yeah, it’s a weird one. Glad you fixed it though!

  2. Thank you. I’d posted a ticket to Yoast support who amongst other things said: “Sometimes strange behavior may be caused by a plugin or theme conflict. The fastest way to rule out conflicts is to deactivate all non-Yoast plugins and switch to a standard theme like Twenty Sixteen.”

    Doing that actually broke something on my site and really it’s a cop out. There must be some way when generating the xml to trim the first line if it’s blank.

    Anyway, solution number 4 worked for me, so thank you very much for documenting this.

    • dja360

      Thanks, Daniel. Always good to help out a fellow DJA!

Leave a Reply