What’s Wrong?
The problem is quite easy to resolve if you are a programmer who considers the unpredictable and any RSS reader developer should consider this. The fast and dirty fix is to TRIM the resulting feed (XML file) and that’s it! The problem is resolved. In a few minutes I added this fix to the resulting feed on our WordPress file.How To Fix This for WordPress?
The file in charge of creating the content is feed.php but the file which loads the header is a small file located in the WordPress root folder, /wp-blog-header.php. This file has a line which calls the required file and adds the header to that. See the below line:1: require_once( dirname(__FILE__) . '/wp-load.php' );
This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.Now, how about a few modifications to the wp-blog-header.php file?
Steps to Follow
First, do a local back-up of the file. It’s located in the WordPress installation root folder, so it should be quite easy to locate it. Now, open the file and let’s write some more lines above and below the line presented above (commented in the code bellow with “this is the line”):1: function callback($buffer)
2: {
3: return (trim($buffer));
4: }
5: ob_start("callback");
6: require_once( dirname(__FILE__) . '/wp-load.php' ); //this is the line
7: ob_end_clean();
1: <?php
2: /**
3: * Loads the WordPress environment and template.
4: *
5: * @package WordPress
6: */
7:
8: if ( !isset($wp_did_header) ) {
9: $wp_did_header = true;
10: function callback($buffer)
11: {
12: return (trim($buffer));
13: }
14: ob_start("callback");
15: require_once( dirname(__FILE__) . '/wp-load.php' );
16: ob_end_clean();
17: wp();
18: require_once( ABSPATH . WPINC . '/template-loader.php' );
19: }
20: ?>
What I’ve Done?
I’m saving the output RSS file into a buffer, so I’m only getting the header. The callback function is returning a trimmed string, which is the buffer – the main XML file for the RSS feed. By trimming the XML file I’ve got rid of the useless new line at the beginning of the file, thus the error is fixed. Something similar is doing the fix-rss-feed plug-in, which is quite useful, but not completely fixing the error sometimes. So, if you need the fixed wp-blog-header.php file, you may do the alteration yourself or you may download the archived file here. Please be advised that this file may only work for some of you and may stop your WordPress site from working correctly. Before overwriting or changing anything in the WordPress core files, please make a back-up. Hopefully, sometimes in the future, the WordPress team will find a fix for this. Until then, I’m hoping this fix will help you. All the best,