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 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
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
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.
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.
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.