Fix WordPress Feed XML Parsing Errors: Delete Blank Lines

Our Feedburner feed was down, and so was the WordPress source feed which showed “XML Parsing Error: XML or text declaration not at start of entity“. And all this while Google reader was correctly tracking our feed, while it was not loading in any web browser!

XML Parsing Error

Firefox showed this error on loading the feed
XML Parsing Error

XML Parsing Error: XML or text declaration not at start of entity Location: https://www.quickonlinetips.com/archives/feed/ Line Number 2, Column 1: ^

Google Chrome revealed some more information
chrome XML Parsing Error

This page contains the following errors: error on line 2 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.

I searched around various forums and blogs for possible causes and found that it was most commonly caused by a Blank line before XML declaration

Basically this error arises if there is a whitespace before an XML declaration (<?xml ... ?>) appears in your feed. The blank line error means that the code has blank lines in it, which can be easily introduced in the WordPress php code by a plugin, theme, or any configuration file.

So basically I had to go looking for blank lines before PHP starting tag
<?php
and after the PHP closing tag
?>

Fixing Blank Line PHP Errors

1. First I deactivated plugins one by one to see if any of them had a coding error. But none of the plugins seemed to cause the error and I activated them all back.

2. Then I logged in via FTP and started checking the wordpress core files. I found that surprisingly many PHP files had blank lines after the closing tag like in wp-config.php in root folder, feed.php in wp-includes to name a few. I downloaded the latest WP2.7.1 version to check if the last autoupdate from WP 2.7 to WP2.7.1 had brought in these blank lines. In fact, the latest WP 2.7.1 version also contains blank lines at end of wp-config-sample.php and feed.php. So I removed the blank lines.

php blank line

3. Then I suspected that I recently altered PHP in my theme configuration files to separate comments and trackbacks. So I checked all my template files, and there it was, a blank line at the end of functions.php. (which was edited earlier to set right the comments count). I deleted the blank line and saved the template.

theme blank line

I suspect that the blank lines in the theme functions.php could be the cause since it was recently changed, but the wordpress core files blank lines could also have caused it. Anyways after deleting all these blank lines, the feed started working instantly and the errors disappeared.

4. Remember to turn off caching by WordPress caching plugins like Wp-cache or WP-supercache, so that you may catch the exact cause of the error.

5. Had this also not worked, I intended to use the ‘Fix RSS Feed WordPress plugin’ which promised to search all folders (except wp-admin and wp-includes directory) if the php file has blank lines in the head and tail line, and then delete blank lines. The plugin author writes that it will delete php files at only the beginning and end of the blank lines, and will not delete the blank lines between documents, so it will not affect the operation of the php programs.

6. Then my Feedburner feed was not updated. So I pinged our feed to Feedburner, but the feed would not update. Then I logged into my Feedburner account > Troubleshooting > Resync Feed. And the Feedburner feed started working instantly.

NOTE: While all feeds were not working in web browsers, surprisingly modern day feed readers are so smart, they can override this error and grab the article correctly. I confirm that I continued to read my latest articles in Google reader and would have never suspected any feed error had a friend not informed me.

Lessons Learnt: Check your feeds regularly and take care of the blank lines when editing PHP files.

55 comments on “Fix WordPress Feed XML Parsing Errors: Delete Blank Lines

  1. Alpesh Nakar says:

    Looks I have been hit too! Will check out tonite. I did customise my theme a lot lately with conditionally tagging in WP and I think this could have caused.

    Thanks for writing this up.

    I was clueless about this :) but did remember you writing about this.

  2. Alpesh Nakar says:

    Update: Yes it was the functions.php that was the culprit.

    Thanks heaps!!!

  3. Kamil Molendys says:

    Thank you very much… It works!

  4. Dadony says:

    I had the same problem… and the fix it. i’m install fix-rss-feed plugin. It works!

  5. Serge Bóinn says:

    Yep, functions.php here as well.
    Thanks so much for your work!

  6. Neel says:

    Yes most of the times the problem is in the function.php file or in the plugins files.

  7. 工作達人 says:

    Your article help me to slove the problem.SO would you mind me to translate it to Chinese?

  8. Michael says:

    Turned out it was the functions.php for me, as well.

    I totally forgot that I had edited it just before upgrading to WP 2.8.4 for a cleaner function…and ended up creating a bunch of needless extra research for myself, to resolve the problem.

    For those of you who didn’t fall into the “functions.php” category…

    You might want to give the Fix-Rss-Feed plugin a try, it quickly removed blank lines from most .php files in the WordPress directories and would save you a lot of time:

    http://wordpress.org/extend/plugins/fix-rss-feed/

    Just wanted to say thanks for mentioning the functions.php one…I am astonished I missed it.

    Cheers,
    Michael

  9. kazooli says:

    Hi there,
    I have been looking for some information wth regards to xml errors in wordpress. As I produce articles, now and then, I create errors by accident.

    Is there anyhting that I can do to correct these errors automatically or do these have to be manually corrected.

    You seem like the right person to ask and so I hope I have not hijacked your post with my queries.

    All the best
    Kazooli

  10. Josh L says:

    Thanks for this post! In my case, it was also the functions.php file, but it was a blank line between two blocks of PHP, rather than at the beginning or end of the file.

  11. Doc4 says:

    Josh L,

    This was the same issue we were having. Thank you for pointing out that spaces between php tags can cause this same malfunction.

  12. Andrei says:

    thank you for this post!
    I finally located the culprit – functions.php – that was causing me headaches.

  13. Shahab khan says:

    Many thanks to you QOT for this article ..it helped me a lot!

  14. Micah says:

    Man, I wish this was as easy as it being a functions.php problem! I went through all the steps but STILL get the same problem as originally described. I am baffled and do not know what to do next!

  15. psycoreownz says:

    uff… you save my life… y tried with the plug-in and doesn’t work, so i start editing all the archives of my template and the ftp server and done! all came back to normally

  16. Clarence says:

    Wow, great post. I was having problem with wordpress for Blackberry and it wouldn’t work, then i found you post, now my blog is accessible from my Blackberry again “blackberry uses xmlrpc”

    Thanks,

  17. moonlight says:

    yes its function.php problems.
    i’m fixed the FSS feed error.

    thz all.

  18. Joseph says:

    I just like to say thanks for this info. I am still trying to fix my RSS Feed, but your info has been very helpful. Fingers crossed!!

  19. RestlessCreative says:

    I found this problem to actually be BLANK LINES at the end of the FUNCTIONS.PHP file. Delete those lines.

  20. Clayton Miller@claytonmiller.com says:

    Thanks for the post. I have read about the whitespace problem. And rereading it made me check again and fixed my problem (that I overlooked). Just wanted to say thanks.

  21. Beta says:

    Thanks you, i want to use this fix feed XML parsingeror guide.

  22. Krish says:

    There are many ways to fix this.. Read the below article..Nice one

    http://www.globinch.com/2010/09/15/wordpress-rss-feed-xml-parsing-error/

  23. angad says:

    THanks alot…. u just saved me thanks… i had almost given up…..

  24. Neil says:

    Hi

    I did all what your post says and I still have the error.. any ideas what it could be?

    • Oxygen says:

      Parse your feed to some XML validator: maybe it will help. Not only blank line could break your rss.

  25. charlotte says:

    Thanks – you helped a lot – it was functions.php for me too.

  26. برامج 2012 says:

    Yep, functions.php here as well.
    Thanks so much for your work!

  27. برامج 2012 says:

    I dont know how can i thank you for this post
    i fixed my rss feed problem by wordpress rss feed fix plugin that you put in the post

    thank you very very very much

  28. Muqthyar says:

    thank a lot, this helped me a lot

  29. Mike says:

    Thnks a lot! was looking for solution for ages ))

  30. Naser @ Tech Blog says:

    Hello,
    Iam getting a different type of error in my wordpress feed: techblazes.com/feed which says: error on line 660 at column 30: Input is not proper UTF-8, indicate encoding !
    Bytes: 0x1C 0x4F 0x70 0x65
    This made my feedburner feed to stop working correctly. Please help me..

Leave a Reply

Your email address will not be published. Required fields are marked *

All comments moderated. Use True name. No irrelevant links. Post useful content.