Fix Broken WordPress RSS Feed Due to HTML Above the XML Declaration

I had the problem that my RSS feed was broken due to HTML that appeared above the XML declaration.

IMPORTANT: This post is not about spaces before the XML declaration in the RSS feed. You can find plenty of WordPress forum posts solving this problem like this.

Im my case, HTML code appeared in my RSS feed before the XML declaration like so:

1
2
3
4
5
6
7
8
9
10
11
	<div style="display:none">
	</div>
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

So, the solution approach was straight forward: Figure out, what put the HTML code there and fix it.

However, it still took me two hours figuring out that this was caused by the WP Facebook OpenGraph plugin. It turned out that a function call creating the plugin’s footer output the code before the XML declaration.

However, the Open Graph plugin is not the point of this post. The point is how you can figure out what is breaking your feed. In numerous forum posts like this you get most helpful hints that you should…

  • …deactivate all plugins to see if this resolves the problem.
  • …switch to the default theme to rule out any theme-specific problems.
  • …reset the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

Well this is basically all there is to it. However, I lost two hours nonetheless. Why? Because I deactivated my plugins one by one and tested in Firefox whether this did fix my feed by continuously reloading my feed and it didn’t. It turned out I should have deleted my browser cache everytime after I deactivated a plugin in order to refresh the retrieval of the feed 👿

So I tinkered around a lot before I deactivated my plugins again and tested the feed directly in the Feed Validator. And after deactivating all plugins my feed worked. Now, reactivating the plugins one by one unearthed the erroneous behavior of the plugin mentioned above. Do I need to say that this plugin was the last in my list that I reactivated? Thank you, Murphy’s Law.

To conclude, do not repeat my mistake. Instead, to test if your plugins break your feed, do it like this:

  1. Deactivate all plugins.
  2. Go to Feed Validator and test your feed.
  3. If your feed works, reactivate the plugins one by one until you find the culprit.

Actually pretty simple.

Posted in PHP, Wordpress