You ever get an error like this from your feeds generated by WordPress?
XML Parsing Error: XML or text declaration not at start of entity
Location: http://www.yoursite.tld/utils/test.xml
Line Number 2, Column 1:<?xml version=”1.0″ encoding=”UTF-8″?>
Somewhere along the line a new line was being placed before the XML declaration in the feeds. This caused an error to display in Firefox and other browsers instead of the feed.
I searched high and low to find where it was coming from. Disabled all me plugins, removed blank lines from code etc. To no avail. Then I noticed that the error was happening on a Mac but not in Windows. So it had to do with something about how Windows, Mac, and Linux/Unix deal with carriage returns and new line characters. I didn’t think I’d ever find the ghost new line (or return) so I tried to find a way to delete it.
Here is the hack/fix. What I’ve done is start an output buffer, and then clear it before the XML/RSS template is loaded.
In the index.php file put ob_start() like this:
<?php
ob_start();
In wp-includes/functions.php add ob_end_clean() to the beginning functions that load the feed templates.
/**
* Load the RDF RSS 0.91 Feed template.
*
* @since 2.1.0
*/
function do_feed_rdf() {
ob_end_clean();
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
}/**
* Load the RSS 1.0 Feed Template
*
* @since 2.1.0
*/
function do_feed_rss() {
ob_end_clean();
load_template( ABSPATH . WPINC . ‘/feed-rss.php’ );
}/**
* Load either the RSS2 comment feed or the RSS2 posts feed.
*
* @since 2.1.0
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
function do_feed_rss2( $for_comments ) {
ob_end_clean();
if ( $for_comments )
load_template( ABSPATH . WPINC . ‘/feed-rss2-comments.php’ );
else
load_template( ABSPATH . WPINC . ‘/feed-rss2.php’ );
}/**
* Load either Atom comment feed or Atom posts feed.
*
* @since 2.1.0
*
* @param bool $for_comments True for the comment feed, false for normal feed.
*/
function do_feed_atom( $for_comments ) {
ob_end_clean();
if ($for_comments)
load_template( ABSPATH . WPINC . ‘/feed-atom-comments.php’);
else
load_template( ABSPATH . WPINC . ‘/feed-atom.php’ );
}
This worked without the change to the index.php file, but I don’t think it should have.
I tried to accomplish this with a plugin, but it wouldn’t work. since this is editing WordPress core files, these changes will need to be made again after an upgrade if the problem persists with the new version.
August 31st, 2009 at 2:45 pm
same problem in my blog gadgetzones.com/feed, my blog engine wordpress-2.8.4…
I do not know what to do for my blog :(
August 31st, 2009 at 2:50 pm
Try disabling all your plugins.
September 7th, 2009 at 9:28 am
I Try disabling all plugins, I am downgrade wordpress-2.8.4 to wordpress-2.7. uninstall wordpress and install new wp engine ( export import content ), but all failed… :(
January 2nd, 2010 at 8:55 pm
still having problems with this one