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.


About the Author:
Sachin D. Brojmohun has extensive experience in terms of graphic design, CSS integration, usability and accessibility as well as in SEO. More about him and the Web Design Bureau of Mauritius here: Web Design Mauritius.

Comments (18)

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.

CommentLuv Enabled
  1. Bruno
    Twitter:
    says:

    I use FeedBurner and no feed errors at all, even with CommentLuv (as you can see) :s
    Bruno recently wrote:
    UK emergency budget

  2. Kurt says:

    I have not updated to wp3 yet on but have been testing wp3 on subdomains. I find the previous look (dashboard look) much better. This one is too light and you know am not such a fan of light colours :S
     
    By the way thanks for sharing the tip above. Bookmarked in case I get this error soon.
    Kurt recently wrote:
    Should I Buy My Own Domain Name?

  3. Very interesting, I hadn’t noticed an issue yet with any of my feeds after upgrading to WordPress 3.  I upgraded all of my blogs and haven’t seen issue yet.

    • Thanks for stopping by Justin. As I said in my conclusion there might be different causes to this error, like an incompatible plugin for example, and you never know. It might all go on smoothly or get busted, I had the second issue :-D .

  4. Thanks for sharing this. Even though I haven’t experienced errors with wordpress 3.0 yet. I will still bookmark your site for reference in the future. Thanks a lot.

  5. TechGopal says:

    i got two problems with my wp 3
    1 :- comments goes automatically on other post ..
    2:- also a problem with image caption code
    can u help me …..

  6. I have already upgarded to WordPress 3.0 and have not been getting any kind of error in it. Not even the feed one you mentioned. Must be some incompatible plugin eh!
    Shiva | Web Magazine recently wrote:
    CouponPress and PremiumPress Discount Coupon Code – July UPDATE-

  7. I had this problem, and your solution worked. Thanks!

  8. Livio Kujur says:

    Thats a superb info for wp users.

    A few days back updated to wp3 but have not found this prob i checked the link http://designcreed.biz/feed/ for feed… but will keep in mind.