WordPress 3.0 might have feed errors. Fix them!
WordPress 3.0 is the new current hip. Everybody is switching to the new platform while fearing crashes or great upheavals in the world of blogging. I’ve been a bit worried about all this for some days before taking the leap of the full WordPress 3.0 upgrade. Everything went on really fine until…
Errors through CommentLuv.
I was commenting on a blog I usually visit. When I activated its CommentLuv app, I was greeted with a “No last blog post found” error that got my eyes growing like saucers before starting squinting in pure disbelief, as if staring for 2 minutes at the error message would give me explanation. First thing I did was to check my RSS feed where I found a nice error on line 5 at column 6: XML declaration allowed only at the start of the document error. It dawned to me that the WordPress 3.0 update might have generated this error.
Recurring feed error.
After some research, there seems that this type of error is frequent in WordPress, whatever the version. So I went out to try several feed correcting plugins for WordPress but whatever the solution tried (even that of clearing all WordPress files from blank lines) it didn’t seem to be able to clear the errors out. According to all that I read, it all comes from some trailing blank lines in the feed code. Having tried everything in vain, the only solution to this was to go back to the good old hand coding.
The fix.
Fixing this error was not an easy task but I found an article over at www.w3it.org. The code is fairly simple and its implementation is easy. All in all it takes the feed generated by the WordPress core and clears it all up from any blank line held around.
What you need to do is to open this file:
wp-includes/feed-rss2.php
Open this file in a text editor and look for this line:
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
$more = 1;
Just underneath it add this code
$out = ob_get_contents();
$out = str_replace(array("\n", "\r", "\t", " "), "", $input);
ob_end_clean();
That’s all! Short and sweet. This code clears all empty lines and hey presto, your feed is restored.
Other feed files?
You might be asking why the wp-includes/feed-rss2.php file? Just because it is the one that is really used in the WordPress feed. You can however do like I did, I opened all the other feed files and stitched them up with the same code.
A final word.
What came out of my perusals over the web on this issue is that the “blank line” error can be generated about anywhere in all the WordPress core or theme files. The current solution corrects all of these in one go but calls for hacking the feed. You’ll find different sources, hacks, solutions or what not on the subject out there and each might have a different root so take a good look at all the possible bugs before testing any solution around.

