On Broken XML in WordPress RSS Feeds
I recently received an email from a reader who was letting me know that my RSS feeds were producing bad XML. Google informed me that this is not an uncommon problem. It appears that there is no silver bullet for fixing this issue, but I thought I’d share the steps I took to get it to work (and those I took that didn’t work).
I viewed the source of the bad feed in Firefox. After copying the XML into Visual Studio and trying to generate a schema, I received an error about the xml declaration. If I removed the <?xml version=”1.0″ encoding=”UTF-8″?> VS was happy. VS saw something before the <?xml. I couldn’t see it, but I was confident something unprintable was there.
My hosting company has a WordPress installer. I setup WP using that a few months ago. I had never updated the files, but have installed some plugins. Some people are under the impression that plugins or themes are the root cause of the issue. I had no luck with deactivating/deleting plugins. Switching themes didn’t help either. I checked out all of the commonly included WP files, looking for extra whitespace. Couldn’t find anything…
I also tried playing with encoding. I made sure the DB was setup to use UTF-8. It hadn’t been, but that didn’t make a difference. I tried upgrading to the most recent WP version. After Vista spent 20 minutes unzipping the WP files I deployed out the upgrade. No dice. Plus I was getting some other errors related to the upgrade and didn’t feel like investigating.
Finally, I simply backed up my current installation and reran the installer on my host’s control panel. I copied the old wp-config.php file contents into the newly created config and loaded the site again. Now I was seeing ?? (double question marks) at the top of all my pages. These ?? were in my wp-config.php file. When I tried the RSS feed, the ?? showed up before the <?xml tag. The unprintable became printable thanks to some copy and pasting. Removing the ?? in wp-config.php allowed me to feed again.
Long story short, I’m really not sure what caused the issue. I’m guessing I saved wp-config through my control panel’s web-based editor at some point. With web.config files, it always drops some unprintable characters in front the of xml declaration. I think it’s time to reread Joel’s post on encoding…