Steve Workman's Blog

Is Wordpress putting whitespace in your XML? Here's how to fix it

Posted on by Steve Workman About 1 min reading time

XML error

Since I started using Feedburner to add adverts into my RSS feed (there are now ads, let me know if they're intrusive), I've been getting errors like the one above in my XML feed. Basically, there's a few new line characters being output by several classes. This means the XML is invalid and services like Feedburner complain, as do some browsers (FF, Opera, Chrome).

In PHP, there's a simple way to fix this, using a buffer and stripping newline characters off the beginning and end. Wordpress have considered this before, and have rejected this method of fixing it because it's generally caused by plug-ins which should fix themselves. Hence, their solution for 3.0: indicating when additional characters are output when the plugin is activiated.

So, I did that for all my plugins. I found that the following were giving me extra characters:

So, I then removed the blank line at the top of each of these files. This got the number of blank lines from 12 to 2, which still isn't enough.

I then re-installed wordpress, thinking one of the core files had become corrupted. Still no valid XML.

More research led me back to the output buffering solution. has a pre-prepared file to resolve this issue. It's a simple install and is well documented. Since putting this fix in, I've had no issues and my RSS feed is back up and running.

I'd still love to know what caused the single line, but I'm glad there's a fix to sort it out.