269

WordPress Remove Blank Line From RSS Feed – wordpress error on line 2 at column 6: XML declaration allowed only at the start of the document

For whatever reason, once in a long while WordPress will just break the RSS feed. Why? God only knows.

Maybe it didn't like a plugin you just added or it just doesn't feel like working that day. Whatever the reason, your WordPress RSS feed has stopped working and all hell has broken loose! Many people are dependent on their RSS feed and heck, at the height of this website before the change I had a good 60 people following me on RSS! WOOT! I know that's not many, but it sure as heck was a traffic kill when the RSS went down!

So if for some reason you get this error when loading your RSS feed in a browser (like Chrome):

wordpress error on line 2 at column 6: XML declaration allowed only at the start of the document

Or it fails to pass the ever vigilant W3C RSS Validator and gives an error such as:

Sorry

This feed does not validate.

  • line 1, column 1: Blank line before XML declaration [help]

DON'T PANIC!

There is a simple solution for this. It doesn't require some crazy plugin. It doesn't require hiring a super hacker geek to fix it AND it won't require hours upon hours of Google'ing for the solution.

Now, if you want to try there are a few possible solutions. You can try:

  1. Reading this helpful article on the RSS Validator site: http://feedvalidator.org/docs/error/WPBlankLine.html
  2. Try the FIX RSS FEED plugin for WordPress (didn't work for my clients site at all)
  3. Paying someone lots of money [like me 🙂 ] to do it for you.

Or you can simply do this yourself. It's REALLY really simply and only require one file upload and one line of code. I'll guide you through the whole process.

1) FIRST. Download the following filehttp://wejn.org/stuff/wejnswpwhitespacefix.php.

If you're a geek you can check it for yourself, but I (Piotr Krzyzek) assure you this file is Virus free. If you don't trust that file, you can download the exact same file from my server which I won't change at all. So you can 100% rest assure that this file is safe from my server. You can get it HERE from my server. But if you download it from my server, rename the file from the “.ph” extension to “.php” so that it will work on your server too.

2) After downloading, upload the .PHP file into your WordPress site ROOT directory. This means wherever the wp-config.php file is. Do NOT upload it into the themes folder, NOR the plugins folder. Only the root directory.

If you don't understand that, it's ok. Leave a comment or poke me a twitter and I'll explain it better.

3) EDIT your index.php file and add the following right after the first line:

include("wejnswpwhitespacefix.php");

So at the end, your index.php should look something like this:


<?php
include("wejnswpwhitespacefix.php");
define('WP_USE_THEMES', true);
require('./wp-blog-header.php');
?>

That's of course a condensed version of the index.php file and your's will probably have lots of comments and stuff in it. But the important thing is to add the include code right at the top.

After that, poof!

Reload the feed page and/or your site and it'll magically work!

It did for us!

Let me know in the comments if this worked for you or if you know of any other better solutions!

  • Thank you doesn’t say enough! After 4 hours of trying to remove white space myself, your fix got everything cleaned up in 5 minutes!

  • Marc Kranat says:

    It worked for me for on a client site after disabling all plugins and switching themes did not work. I still see the same
    Error Details: The Jetpack server could not communicate with your site’s XML-RPC URL. Please check to make sure http://domain.com/xmlrpc.php is working properly. It should show ‘XML?RPC server accepts POST requests only.’ on a line by itself when viewed in a browser and should not have any blank links or extra output anywhere.
    that started at the same time and i’d thought were related issue.

  • Glad to have helped. 🙂

  • Thanks a ton, piotr. it worked 🙂

  • ertu says:

    thank you, is great

  • Josh says:

    Not sure why I can’t figure it out, but I followed the instructions and still the same issue. I’d really appreciate any assistance!

  • Tish says:

    Thank so much it worked for me

  • Niko says:

    Awesome tip, thank you man !
    Helped a lot for me 🙂

  • Hey Josh,

    sorry about the late reply. Sadly this fix doesn’t work always: why? Because then it means that the issue isn’t purely an RSS feed issue, there must be some bad content somewhere. Something is feeding your RSS feed some bad code/data and it’s not liking it. You’ll have to do some digging for that.

  • dskanth says:

    It did work, but is it a preferred way of solving it? What if WordPress gets updated tomorrow, and the index.php file is modified?

    • Glad it worked for you.

      Though you’re right: if WP get’s updated tomorrow and the index.php file changes … well, then you’ll have to redo the file changes. 🙁

      As far as I know this is one of the ways to get this issue resolved.

      Hm … would it be the preferred way? To me, yes. It’s quick and worked for most people. But it’s really more of a bandaid fix rather than an actual problem solution. If you value your time and want things to ‘just work’: yes it’s the preferred method. If you want to dig deep and find the root cause in your unique situation/setup: then have at it and start discovering what’s causing the underlying issue and in that case no, my solution isn’t the preferred method.

      I think the most preferred solution would be to make a plugin that does this automagically though. Hm, I should get that done once these days. 🙂

  • Xuân Ngh?a says:

    Great!! Tks you very much 🙂

  • Céline says:

    Thank you so much for your tip !!!

  • AnasAbubackerV says:

    Yes. it is worked magically.
    Really Thanks.

  • jeff says:

    thanks for this fix…worked great solved my sitemap issue

  • ALLOFTHEMES.COM says:

    Thank you alot dude! U have good joob done! Works perfectly!

  • […] an hour of Google searching, I found the solution in this Peter Krzyzek’s post, and I can never be grateful enough to the author for having solved this […]

  • Carlos says:

    You SIR are a GENIUS!

  • Marcelo says:

    Dont work for me, i am running on WP 4.0

    WHen i add the include the sites crashes and blank page its show

    PD: Sorry my english its bad

  • Lesclar says:

    Thank you, probleme solved

  • thank you sir. I hope your business is always smooth 😉

  • Fred Reillier says:

    Didn’t work neither…

  • Farid says:

    you saved my day man. Thanks a lot

  • badri says:

    You’re a GENIUS !… thank u

  • Fengzi says:

    Thank you! It’s working!

  • Irfan says:

    Wow.. it works, thanks a lot

  • […] blank links to the top of my blogs HTML code. Feedburner doesn’t like this. I fixed it using this guide and a little PHP file in my root folder. Pretty easy stuff […]

  • ejll105 says:

    POOF. and it worked! No idea how, but great trick! can’t thank you enough.

  • Huge help – thanks Piotr! You da man.

    • Subject: Re: Comment on WordPress Remove Blank Line From RSS Feed – wordpress error on line 2 at column 6: XML declaration allowed only at the start of the document

  • rahulcoolexam says:

    Sir, it really worked for me . I appreciate your work . Thank You.

  • […] WordPress Remove Blank Line From RSS Feed – wordpress error on line 2 at column 6: XML declaration… […]

  • Suko Basuki says:

    Awesome tip. Work great for me. Thank You.

  • Romulo says:

    It works!!! Thanks a lot dude!

  • Anna Cinal says:

    Dzi?ki za artyku?, wszystko dzia?a:)

  • Derek Clair says:

    Exactly as perscribed, thanks doc!

  • Nathusminus says:

    Thank you so much ! It works for me 🙂

  • Biren says:

    can some fix this problem of wordpress website “RSS Error: WP HTTP Error: couldn’t connect to host”

  • I honestly was skeptical of this and am pleased to announce it worked for me as well (February 2016!!) THANK YOU!!!!!

  • Tnx mate! It did work!

  • Andreas Kroppen says:

    Unbelievabk´´le, it works 🙂

  • ????? ?????????? says:

    THANK YOU!!!

  • just instal fix-rss-feed, my web solved, thx sir

  • John says:

    Hey there…does this have to be redone after every new WordPress core software update? I notice index.php resets everytime to remove the code I think. Also, would this fix categories not showing on blog posts and being listed in the sitemap too? 🙂

  • Dean Wormald says:

    Worked perfectly, thanks heaps for this 🙂

  • Jack says:

    Thanks! Still working in April 2017!

  • zendika says:

    thanks, its really work for me 😀

    http://kepodonk.com/sitemap.xml

  • Works for me. Thanks a lot. You save me.

  • peter meehan says:

    fantastic thank you for that. its was driving me nuts. my problem was with the xml sitemap not showing

  • JUAN says:

    This is an old video and you could think that it is not applicable now in 2018 but for me it has worked perfectly, this is is the ultimate solution. GRACIAS

  • >