257

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!

  • Joseph Alvini

    More people need to read this article and comment that this fix is one of the only EASY ones that actually fix it. I find it unbelievable that there are 1000 people on the wordpress forum which is only 2 spots up on the Google search engine and thee advice that they give is awful.

    If people would take the time to actually read your material and then post how it DID Work for them we would have a lot less people lost in code.

    Anyway thanks for this awesome fix.

  • HUZZAH!!!
    That was amazing! I’ve been trying to fix this for a client all afternoon, tried manually pulling blanks form a few files tried the plugin (caught 2008 errors). Nothing worked.

    Took 2 minutes to try this as a last ditch effort and viola!

    A thousand thanks yous!

  • DLS

    Thanks for sharing. This worked after not be able to find the offending file that was inserting the blank line.

  • Pingback: thestudiosource.com » Overcoming technical difficulties, or how to look really clever()

  • mamun

    thankssssssssssssssssssssssssssssssssssssssssssssss you very muchhhhhhhhhhhhhhhhhhhhhhhh dudeeeeeeeeeee.

  • sakhan24

    For of all i had problems with my rss feed and i downloaded the fix rss feed plugin i installed it and it mess every thing so it took me a loot of time to recover my website while searching for the solution i came across your blog and applied technique and boom it working great

    thank you for a nice share

  • Bingo!

  • BGeo

    I tried all the above options… Plugin, custome code to remove blank lines and pluging deactiations etc.. But finally the article at globinch helped me. I searched for all my recently changed files and removed spaces as mentioned there..
    http://www.globinch.com/2010/09/15/wordpress-rss-feed-xml-parsing-error/

  • I uploaded the file and added the line. It didn’t work for me. Am I doing smthn wrong?
    I’ve tried all the other ways as well. Nothing works.

    my blog: http://rheumatologistdelhi.com

    error: This page contains the following errors:

    error on line 1 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.

    • Hey Shivani,

      Hm the file should have worked. Where exactly did you upload the file to? I mean, which directory? If you use FTP, then you should upload it (most likely) into the same folder into which is logs you into.

      So if you FTP in and you see folders like “public_html”, then you need to traverse deeper into the website directory.

      You should upload it to the same level as the folders “wp-content” “wp-includes” and those folders. NOT into any of those, but it should be in the same folder which holds those folders.
      I also made an error in my post, I just noticed. I should have been more specific. You should add the line (step #3) into your THEMES index.php file. So into the file: wp-content/themes/YOURTHEME/index.php …

      Good luck! If it still doesn’t solve it let me know. Contact me on Twitter and I’ll look more into it!

      –PK

  • Hi,

    I’ve done exactly what you have mentioned. It doesn’t work.
    I’d like to share some more details with you.
    1. I seem to have 2 rss feeds here. One is RSS 2 and the other is something called Atom.
    2. http://www.rheumatologistdelhi.com/feed gives an error
    3. http://www.rheumatologistdelhi.com/feed/atom/ shows coding. I notice here that there are blank spaces in the beginning. Where can I remove these? Where are they found? And do I need to keep just one RSS?
    4. There is also something called comments rss.
    5. Here is a list of the RSS files that I have on the FTP:
    wp-commentsrss2.php
    wp-feed.php
    wp-rss.php
    wp-rss2.php
    Should I delete any of them or keep all?

    • Hey again Shivani,

      Sorry that what we tried didn’t work. Having those “2” feeds is ok. It’s not two different ones. It’s just two difference versions/formats of it. Same thing but two different forms. So don’t worry about that.

      You don’t want to delete any of those files. Your WordPress install wouldn’t be too happy with that. You can safely leave those files.

      As for “comments RSS” that is just an RSS feed of the comments only. You can leave that too. Thus you should leave all those files.

      I took a look at your RSS and I see the problem. Hm, sadly this exact problem was fixed by the way in my article (hence why I wrote about it). Another useful reader commented and left a link to a site which might help. It’s in the comments on this article.

      That articles lists several manual things you can try, but one thing to try before trying all the things it says … is try downloading a plugin (from that linked article) called: fix-rss-feed

      Try that out. If it doesn’t work, try reading that article. Seems some people had success with it.

      IF that still doesn’t work, we can talk privately over chat and I’ll solve it for you by hand 🙂

      Cheers,
      –PK

  • And this is the RSS related code that exists in the footer:

    <a class="rss" href="”> <a href="”> ^
    <!– queries. seconds. –>

  • Charly ASAP

    1000’s thanks. nice hack. It works fine for me.

    I include it directly in my plugin not in index. It’s working fine. You can do it with a wp_head filter.

    • Wow, that is a great idea! To include that in a plugin and wp_head! I’ll have to give that a try because it really would simplify a lot of things for many people!

      Thanks for the suggestion.

      –PK

    • Vin Furlong

      Hi, Could you tell me how you do this, IE What file needs to be edited.
      Your help would be greatly appreciated

  • Brion Lion Zion

    wooooooooow!

    after dayyyyys of pulling my hair off. this solution just solved it straight away.

    thanks man

  • Nik Parker

    Hi,

    Thanks so much for this. I was pulling my hair out. Two hours trying to sort it out and this finally resolved it.

    Good man thanks 🙂

    Nik

  • Peter

    Fantastic… just fantastic! It works!

  • Fabio

    Thank you for support.

    This problem is not easy but with article, all resolved.

    Congratulations

  • Getting rid of those extra spaces on one of my client’s WordPress site had my head spinning until I arrived here. This worked perfectly for me and I was able to burn the feed to Feedburner which is what I had been trying to do. Thanks so much.

  • ?????????

    [RU] ????????. ? ????????
    [EN] Work. I checked

    • I don’t get it … it worked for the english version … but for the russian it didn’t?

  • This method with the code even works on Russian WordPress http://ru.wordpress.org/

  • Everything works fine even on scripts for Russia:) Author fellow, THANKS!

  • We’ve been having this problem with the RSS feed validation error for some time now. Not only was it not validating with the w3c, but iTunes was also returning an error. Did not realize that it could be so easily fixed. You have our sincerest gratitude.

  • Vladimir

    Long time could not fix, rescued people gave a link to this site. Excellent, worked! Thank you very much. And understandably stated.

  • Thanks awesome post !!! i tried to make it work thousand times…. i added the file to my root directory but didnt know where to include it in my index.php file…
    take a look at my index file

    ////////hidden/////barred//////////////

  • thanks for your post… at least I know I’m not alone with this problem which has been driving me crazy!!
    However I’ve tried your solution and checked out my code for spaces, and I’m still stuck with the error 🙁

    Any ideas?

    • Hey Greg,

      Sorry he solution didn’t work out for you. As for a fix, this usually works. Hm….

      Where did you place the file? We’ll start debugging from there.

  • My problem solved…. thanks for the reply… the feed problem was caused by one of my plugins name “Series”..it was deactivated and the issue is solved… thanks alot !!

  • Greg

    Hi Piotr,

    OK, well I have the file placed in the public_html at the same level as WP-Config.php.

    The reference code is placed in the top of index.php in my Theme (although I have tried it in the index.php at root level also)

    this is the site: http://pimpmyclothes.co.uk

    By the way…On disabling all plugins I was still receiving a line code error, although it was slightly different, so although plugins are affecting it, there are still errors with no plugins. This is my first custom built WP theme so probably my messy code is at fault. If you can suggest a solution I would be grateful. thanks.

  • Thanks, dude. Worked like a charm for me!

  • thank you thank you thank you thank you! yahoo, thank you! totally worked and fixed the prob!

  • After your procedure I have more errors!

    Warning: Cannot modify header information – headers already sent in …feed-rss2.php on line 8
    Validator sayes:
    This feed does not validate.
    line 1, column 0: Undefined root element: br [help]

    line 2, column 0: XML parsing error: :2:0: junk after document element [help]
    Warning: Cannot modify header information – headers already sent in …

  • after procedure I have more errors!
    —————
    This feed does not validate.
    line 1, column 0: Undefined root element: br [help]

    line 2, column 0: XML parsing error: :2:0: junk after document element [help]
    Warning: Cannot modify header information – headers already sent in …
    —————

    and text of wp-super-cache disappeared from the bottom of webpage

    • Eek! That’s not good. I’ll contact you directly through e-mail so we can work this out!

  • Hirocking

    Hi,
    This worked here too!!!!!!!!!!!!!!!!
    You saved me so much time!
    Thanks!

    from Japan

  • Paige

    Amazing! I worked on this problem for hours this morning…it disappeared. And then the problem reappeared later tonight. As I am building a website (and have worked on it all day)– it means that it’s hard to pinpoint which change made it “break”. Thankfully — your hack cleared the problem right out. I am very very grateful.

  • Hello,
    I was excited when I found your site, but the fix didn’t work. I wonder it’s because I get this message:
    error on line 4 at column 6: XML declaration allowed only at the start of the document?

    Notice it says line 4, not 2.

    What do you think? I appreciate any help.

    Best regards,
    Gabriel

    • Hey,

      Yes, it actually goes make a difference. I means there is something more wrong. Or some plugin is adding extra lines where it shouldn’t. What that exactly means? I’m not sure. Try doing the standard fixes first: change WP theme, disable all plugins. If that doesn’t solve it. Hmm, I haven’t figured out a solution to that yet. Sorry 🙁

      –PK

  • Joel Villarini

    Worked like a charm! THANK YOU very very much!

    • My Please Joel! I’m glad that I was able to help!

  • :bowdown: thank you for the fix, so easy and worked instantly. Thanks for taking the time to post this!

  • kjc

    Thanks – worked like a charm!

  • With one of my sites the nextGen gallery plugin was causing this problem.. with another site I think the plugin also makes a ruckuss but the feed readers still display them correctly

    • The nextgen plugin? Interesting. Good to know that ‘that’ was the problem! Thanks!

  • I tried this,emptied cache,but still it is showing this error

    This feed does not validate.

    *

    Server returned HTTP Error 500: Internal Server Error [help]

    *

    line 1, column 0: Undefined root element: script [help]

    *

    line 2, column 9: XML parsing error: :2:9: junk after document element [help]

    Can you help me out on how to solve this feed problem,I see that it is working by going directly to the feed,but I am not able to use it with dlvr
    Thanks

    • Hey Rahul,

      Thanks for commenting. Check your e-mail. We’ll try to work it out. Though the error you receive isn’t related to the error I wrote my article about. No worries, we’ll get it solved.

      –PK

  • Thank you soooo much for this. I have a feed that is specifically for a feed, so it’s

    http://www.domainname.com/category/categoryname/feed/

    what file do i need to update to correct the whitespace issue for that feed?

    I already updated the index.php for the main feed.

    Thank you again!!!

    • Hey Mike,

      Thanks for commenting!

      For editing, you need to edit the root index.php file. Include the fix script from there. If you need any more help contact me by e-mail. You can find it on the contact page. 🙂

      –PK

  • Thanks for this solution, it worked perfectly for me! However it is causing a small issue on my site. If I edit an page that has images without quotation marks in the code (as in: img src=http://imageurl.jpg rather than img src=”http://imageurl.jpg”), the images will then come up broken. Any ideas on this?

    • Hey Ashley,

      if you do not use quotes then that is improper programming. Think of it as the ‘law’ of the internet and internet browsers. The quotes are required for a tags.

      It’s like trying to make coffee or tea with cold water … you might get something, but it’s just wrong.

      So, you have to use the “” in the img tag. It has to be: img src=”http://www.example.com/image1.jpg”. You can also use single quotes. 🙂

      Good luck,

      — PK

  • Reysbro

    Thanks, worked like a charm after several days of going through virtually every php file to no avail.
    Anyway, RSS and RSS2 work fine, although I’m getting a blank line in my ATOM feed. Is there a way to modify the code so it output where the blank is found? I’d really like to get to the source of it.
    Thanks again!

  • you saved my sleepless debuggin nights! i’m gonna write an article about this! i found out that my feeds were missing and i coundn’t fix them! thank you!

  • Thanks for the fix, but it’s still not working – i’m tearing my hair out! I’ve tried manually removing whitespace, individually deactivating plugins, the fix plugin and finally your solution, to no avail. Interestingly the atom feed (/feed/atom/) seems to be fine, just not the /feed/ page itself. Any suggestions?

    • ..and like magic, it’s fixed! I think it was posting here that did it… sod’s law…

  • I am not a technical person and having to learn all this on my own. I have a question about finding the ‘root directory’. I have a hosting site so I’m not sure if I have to go there to find my ‘root directory’ or if it is within the site itself. I would really appreciate some assistance with this. Thank you.

    • Hey Sally,

      I sent you an e-mail. I hope it explains everything.

      The root directory is the home directory where your site lives. It’s where index.php is. Usually the first folder you see when you log in via FTP.

      –Peter

  • Hi Piotr,

    feedvalidator.org did the trick for me, I tried everything (manual checks on all PHP files, injecting your code to the index, updating to latest WP) but with no avail, and finally when about to give up, I ran the feed through that validator, and guess what, the reason it was not showing was due to an iframe embed code in one of the posts. So people, be very careful what you publish! 🙂

    Cheers mate, and keep up the great work!

  • Hi Piotr,
    I tried this out and ended up having this replace my site and rss feed. From reading the comments this has not happened to anyone else. https://skitch.com/shackep/fb3b8/llcomm.org Did I miss something? Does this work if I am working on a wordpress multisite?

    • Nevermind. I was adding the file via ssh and did not copy and paste in all of the .php document.

  • Works like a charm. Thank you for sharing this!

  • Hi Piotr,

    I tried your fix but it still did not seem to work. I double checked and I did do all the steps plus I also removed spaces in the php files. Any other idea on what I can try?

    Thanks

    • And of course now it is working! HA

  • Thanks – tried 3 things already and then found this page .. great solution cheers

  • Thank you so much for all your time and effort you’ve put in this article.
    Unfortunately I can’t seem to find a fix. And i’ve tried a lot.
    The Problem: http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.tokorose.nl%2Ffeed%2F

    I hope you can help me out.
    Thanks!

    • Hey Rose!

      Sorry that your RSS feed doesn’t work yet. Seems like the problem is so far, that your RSS feed doesn’t seem to exist!

      I even tried to find your RSS feed directly on your site and I can’t find it. Can you post a link directly to it? We can start from there.

      –PK

  • Rick

    hm, i got a blank page with your solution and the rss feed doenst work too 🙁

    any ideas? using wordpress 3.1.4

    • Hey Rick! I’d e-mail you directly to try to help you though you’re using one of those e-mail anonymizers. So:

      If you did my solution and you get a blank page, that means something went wrong along the way. I’m eventually going to put up a video of how to enable the fix, until then. e-mail me at info@piotrkrzyzek.com and I’ll try to help you. Try going through the steps again and make sure everything was added properly. Without knowing more information from your end I can’t really help you.

      E-mail me and we’ll talk.

  • Asgoth

    Works perfectly with WordPress 3.2! Thanks! 🙂

  • Works for me!!! I’m using it with WPMU (WordPress 3.1). THANKS A LOT !!!

  • Pingback: Generated Errors in Wordpress : My Blag()

  • Jop

    Works great !
    Thx !

  • I followed your instructions and still get the blank line error – any suggestions, please?

  • Nicholas

    Cool! 😀 you should make this as a plugin

    • Hey Nicholas,

      I should make it into a plugin. I’ll hire it out soon. Good idea!

      –PK

  • I did as per your recommendations but I still have error message(chrome) as below

    error on line 241 at column 30: Extra content at the end of the document

    Any additional tweak required?

    Thanks

  • It works for me. Thanks! 😀

  • Genius. many thanks for the fix .

  • Myrto

    Hello Piotr! thank you very much for the tip! it worked :)))

  • Val

    You are my hero ! Just great.
    Thanks a lot

  • Yati

    Great one! Thank you!

  • chris

    thanks 😉

  • Hmm, post feed works but the comments feed does not well i dont know why.. 🙁

    Your fix is in the theme dir with the php file and in the wp content dir where config file is at…

  • Thank you so much! I have been struggling with this for days and have been insanely frustrated. I am SO glad I found this website. It was such an easy fix and voila my feed was working again. I am so grateful. Thanks again!

  • Tom

    HA! Now I can take a shower and not sit here all day stinking up the place!! Simple fix… after reading a bunch of gibberish from feedValidator and even worse comments from wordpress.org bulletin boards… this took about 2 minutes and it works. (two minutes because I backed-up the entire site even though you assure readers it’s virus-free … i’m not a geek, just cautious)

    Thanks!

  • Thanks a lot, save me a lot of time 🙂

  • Jenny

    Thank you!! I couldn’t get it to work for a while but realised it’s because I’ve installed wordpress into a subdirectory and therefore had to put the file into a different folder.

    So pleased.

  • Jessica

    OMG THANK YOU! <3

  • jspm

    Thank you for sharing this Piotr.
    Unfortunately, couldn´t get to work using your instructions above. Must be doing something wrong.

    1) Upload php file to SAME directory as WP-CONFIG – yes, that´s ok. I got WP in a subdirectory (blog) so i put it there together with the wp-config file.
    2) Edit index.php – this looked easy because the ONLY index.php file that looks like the one you describe above is OUTSIDE the wp-content folder.

    Then things start to get confusing when you say you made an error in the original post (Shivani Garg September 16, 2010) and that i should really edit my THEMES index file? My theme index file is blank.

    Any thoughts appreciated

    • Hey there,

      I’m sorry about all the confusion. I’ll clear up the post today and I’ll e-mail to help you get it resolved. If anything, contact me via my contact page or social media and I’ll what I can do.

      –PK

  • Thanks…worked great. For those who could not get it to work…here’s a tip.

    When I first tried it, I added the line to my themes index.php file. I then realized that it should be added to the index.php file in the root folder (DUH). Thanks again.

    • Thanks for the updates/corrects Dwayne.

      Yes, it’s in the root folder of WordPress … not the root folder of your theme.

      Cheers mate.

  • Hiya there, i just wanted to pass by to make a correction for the people that cant get it working..
    You should remove the ?> at the end of the line, “?>” is what may be causing all the blank lines at list with the new version of wordpress but ok you may want to ask ok then if i remove all the ?> of my .php files will problem be solved? , answer is no don’t, expect that will happen. Anyway the point is you should have your index.php file look like this:

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

    instead of:

    Just remove the ?> a the end of the line.

    Cheers,
    Veronica 😛

  • Chymmi

    THANKS !!!!

  • cadacual

    Thanks a lot, save me a lot of time
    Gracias, me has ahorrado muchísimo tiempo

  • alex

    Just wanted to say thank you, this problem had been doing my head in for weeks and after stumbling across your post its taken about 5 seconds to fix! you now have 1 more subscriber to your RSS feed

    thanks again

  • Brandon

    For me, the fix was “resetting” the permalinks (Settings -> Permalinks). I have a custom permalink structure “/%category%/%postname%/”. I changed it back to the default, saved, then changed it back to the custom structure. Then the feed started working.

    So if none of these fixes are working for you, try the permalinks!

  • YES!

    Finally, after ten days of losing traffic. Thank you SO much. When we meet, the first round is on me.

    Cheers,
    Rick

  • Jo

    Thanks for this, which works well.

    I just have a question. What happens whenever I (auto)update WordPress (new versions etc)? Does the index.php file get overwritten? In that case, the fix would disappear???

    • Hey Jo,

      IF the WordPress update changed the index.php file, yes it would.

      Though, it’s pretty simple to add the fix back.

      Glad it worked for you! 🙂

  • Thanks for the post but unfortunatly it did not work for me.

    After running the validator I got the following results: http://feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.exponentialtraining.com%2Fnews%2Ffeed

    This shows two blanks spaces above the XML tag.

    I tried your instructions which did not remove the problem as well as looking for white space within my theme and disabling all plugins.

    I am stuck for a reason why this is not working?

    I hope you can help!

    James

  • Poland rulezzz 🙂 Nice fix please change for Worpdress 3.3.1 include line to:

    include(‘./wejnswpwhitespacefix.php’);

    that one doesn’t work
    include(‘wejnswpwhitespacefix.php’);

  • Piotr – You are a life saver. I’m sure you’ve probably been told that before, but I mean it!
    I had been searching feverishly trying to find a fix to my broken feed, and after much hair
    loss and ground teeth – your solution worked!

    Thanks so much for your kindness in helping others!

  • Simon Holmes

    Life saver. Thank you so much for this. Without your kindness, I’d be up shit creek without a paddle! Nice one!

  • Hi Piotr,

    after 6 hrs fumbling around I finally solved that issue. But I´d like to add something:
    If your wordpress installation is NOT in the main folder of your server but somewhere else you have to adapt the path to make this work. Put wejns.php file in the same directory where the wp-config.php is.

    Set the SAME path as in the require-line:

    is obsolete in php by the way)

    Do NOT use “example.php” but ‘example.php’ when addressing wejn´s php-file. ” .php” is not working!

    Thank you for psoting this buddy! When you ever come to Germany the drinks will go on me!!

    • Beer and Germany … hmm, sounds like a good road trip to me! Though I’ll insist on going during October Fest!

    • oliver

      for some reason some lines are missing here after SAME path:

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

      Funny thing is that all browsers (and w3c feed validator say: feed is now valid) and Chrome is still f*cking around.

    • Indeed, don’t use “xxx” but ‘xxx’ It worked! Yeaaaaaah! Thanks @chykalophiagroup:disqus + Oliver

      • Ah yes, the good ol quotes issues. Good pointing that out. Thanks!

  • …by the way: Does anyone has any idea where this freaking bug is coming from (ya, I know: blank lines) But where the hell do they come from?

    • This is a very very good question.

      Sometimes it comes from two plugins not working nicely with each other. Other times it’s a plugin that wasn’t made correctly or for some reason ‘broke’. I had one instance where all I needed to do was ‘reset’ the plugins and the problem went away. It’s so weird.

      Other issues may be incorrectly formatted posts which don’t translate well into the RSS feeds.

      I don’t know the exact reason, but I know there are several possibilities.

  • Eres un dios, perdí mi tiempo revisando en los foros de wordpress cuando tienes la solución más simple. MUCHAS GRACIAS!!!

    • English translation (for other readers): “You are a god, I lost my time reviewing wordpress forums when you have the simplest solution. THANK YOU!”

      I’m glad this was able to help. 🙂

  • DanielleBN

    Thank you, it worked perfectly!
    Cheers!

  • Raja

    Thank youuuuu….
    🙂

  • Thanks!

    This fixed my RSS feed and also my Yoast SEO plugin sitemap problem. I’m using elegantthemes Chameleon theme.

    The is the sensible solution to the problem I think, rather than fixing whitespace problems in tons of files which would be reverted when updates arrive.

  • Pingback: Worpress error on line 2 at column 6: XML declaration allowed only at the start of the document | Bryan Veloso()

  • Thank you Sir and God Bless

  • WOW, amazingly easy and effective! I’ve spent so much time trying to fix my RSS feed and then you came and solved all my problems in less then a minute!
    Thank you, thank you thank you!!!

  • This didn’t work for me.

  • THANK YOU SO MUCH!!!
    Having your rss feed broke is so frustrating when you have many followers and depend on them.
    This fix worked flawlessly!

    Don’t forget to clear cash and reload http://yoursite.com/feed page

  • Emily

    Works perfectly! Thank you so much.

  • Mia

    Hey there, saw this post and jumped for joy… ALMOST… until I tried both your instructions and the fix rss plugin. It seems that your instructions only fixed the issue in Safari on Mac OSX.. still doesnt work in firefox or google chrome for Mac.

    Can you please help??

    My feed is on feedburner…. http://feeds.feedburner.com/districtweb

    • Hey Mia,

      Just tried it and it seems to work fine for me where on Chrome and Firefox in Linux.

  • Thank you, thank you. Worked to fix site I was working on – http://spottedsheepyarnshoppe.com

  • niko

    Thanks for this, i’m really close to solving this bug, Followed all the steps but now i get a new error.

    error on line 8 at column 1: error parsing attribute name

  • woah! really neat.. thnks.. worked for me… but still dint figure out how did this problem occur! o.O

    • There are many many reasons. One could be a plugin conflict, another could be an extra line of code somewhere, or another could be a incorrectly set post. Yes, that’s actually a possibility: somewhere, somehow WordPress didn’t like a letter or character in your post, and it messes up the whole RSS feed! How? I dunno yet. But it’s possible.

  • Jan

    I have the problem with Firefox en not with IE.

    1. I try FIX RSS FEED, but does niet work.
    2. I tree your solotion, but it doet not work.

    A. FIRST. I Download the following file: http://wejn.org/stuff/wejnswpwhitespacefix.php.
    B. I saved the file on:
    C:\dev\xampp\htdocs\wordpress
    (wherever the wp-config.php file is).
    C. I aded the following right after the first line of
    C:\dev\xampp\htdocs\wordpress\index.php

    The result is:

    But I still getting the eroor on Firefox:

    XML Parsing Error: XML or text declaration not at start of entity”
    Location: http://localhost/wordpress/?feed=rss2

    Line number 2, column 1:

  • Jan

    It works without your solution, but i don’t know how.

  • byron

    You, Sir, are a gentleman and a scholar. Thank you.

  • Wow, thanks for this, Piotr.

    I looked on lots of blogs and forums but your site is the only place that provides an easy-to-use solution. I was a little unsure about downloading a file from your server but everything worked fine and your instructions were easy to follow.

    Thanks again.

    • Hey Andrew,

      Thanks for commenting. I can completely understand the worrying about downloading from someone else’s site; I haven’t exactly been able to figure out a good solution to make people feel safer about it, do you have any ideas for it?

      –PK

      • Maybe you could package it better because I was unsure about downloading a file ending in .ph. You could create a brief instruction manual and add it to your .ph file in a zip file. People may be more confident about downloading a zip file. Maybe you could create a professional looking download page for it too.

  • dan

    I’m getting mad! Nothing works, even your solution didn’t work.
    I spend 9 hours at the Internet today, without success.
    What should I additionally try?

    • EK! I recommend hiring on somebody to dig into your site and see what’s going on.

      It’s VERY possible that even after trying “everything” the problem is potentially your blog posts (or pages). Well, the content inside of it. I’ve seen the content wreck havock on the RSS feeds before. Worth a try to clear out your blog (backup of coruse!) and see what happens.

      –PK

  • Debbie Campbell

    Hmm – I was hoping this would work, but I think something serious is going on with my client’s site:

    http://blog.theseedcompany.org/feed/

    I tried deleting spaces in files, the Fix RSS Feed plugin, and your file, none of these worked. But the problem is only with /feed/, /comments/feed/ is perfectly fine. Any suggestions on what to try next?

    • Hello Debbie,

      I looked at your feeds and they work just fine for me. I even tried running it through the industry standard feed validator and it passes with flying colours.

      http://validator.w3.org/appc/check.cgi?url=http%3A%2F%2Fblog.theseedcompany.org%2Ffeed%2F

      • Debbie Campbell

        Something I did on the 28th worked, they had some kind of caching in place that wasn’t a plugin. So not quite sure which effort fixed it.

        • Hehe, don’t you just ‘love’ that about fixing issues online? Something eventually magically fixes it, dunno what but it works now so everyone is happy … now let’s not let anyone touch it 🙂

  • Hi Piotr

    Thanks for all your efforts on this – followed your instructions perfectly – uploaded to the root and changed the index file as indicated but still the same problem. i have tried all the other solutions to no avail – I use rackspace CDN and variou caching plug-ins – wondering if this might be causing a delay in the fix – the feed works in safari but nothing else – any further suggestions would be greatly appreciated.

    best wishes

    tom

    • Hey Tom,

      Sorry to hear that you still have this problem. That really does suck! It is possible that the caching plugins are causing problems. So far, I’ve seen three things that can potentially help you:

      1) Removing caching, clear browser cache as well. And then recheck again once your site is running 100% and nothing cached.
      2) Go through your .PHP files and make sure no files have trailing lines at the end of the files.
      3) Backup all your posts, pages, files, uploads and everything. This is the nuclear option. Wipe every single thing off of your server. Delete wordpress, any uploads, .htaccess files, remove every single trace of any file from your host. Then reinstall wordpress. Try the feed? If it’s still broken … then there most likely is a problem with your host WP installation. Then add back the theme. Is the feed still working? Yes? Then procced to add back plugins, and your custom settings. Now it’s time to add your pages and posts back in. If your feed breaks only after adding your posts and/or pages, then you know you have some offending content that for one reason or another is screwing with your feed. I have seen a stray foreign character destroy a feed before…. how? It’s WordPress, the codebase isn’t the best. 🙂

      If you need any help doing all that, let me know and I’ll see what I can do to help.

      • Thanks for taking the time to reply – i am going to check all my PHP file as suggested – i do not fancy the ‘nuclear’ option much 😉 – just as a matter of interest – you may or may not know – but my SERPs results differ on safari then on other browser (cache cleared each time) I was wondering since my SERP results aare higher on Safari and Safari is the only browser that responds to my RSS whether there might be a connection. Hmmmmm??
        Best Wishes
        Tom

  • This worked for me. Is this a file I have to leave in WordPress core, or just run once?

  • Alex

    This works fine and saved me a lot of time. Thanks a million!!

    Now, I just want to ask why can’t I remove the file as it gives the error if I do it?

    • The solution I posted here, the file, is more like a bandage than a fix. So, take off the bandage and the leak starts again 🙂

      • Alex

        Thanks, again!

  • Beautiful! It worked perfectly first time. Wish I had found you sooner, but better late than never. Thanks!

  • Pingback: » Wordpress RSS Feed Error Tech.Russ Catanach()

  • Ben

    Beautiful, thanks! I was going insane looking for the errant whitespace, but this fix worked a treat.

    Thanks again.

  • Christophe

    Wow!! THANKS A LOT! like Ben before me, I was loosing hope when I found your post. Great job.

  • You’re the best!
    I have hours trying to fix your problem and fixed it in a minute.

    Thanks so much

  • Nik

    THANK YOU!!! YOU SAVED ME!!!

  • Thank, i read many thing on the web, you are the only one who solve the problem
    thank.

  • Thank, i read many thing on the web, you are the only one who solve the problem
    thank.

  • Addison

    Didn’t work. I downloaded the file, put it in my root directory (where the wp-config file is) added the include in my index.php file. Nothing worked.

  • Addison

    Didn’t work. I downloaded the file, put it in my root directory (where the wp-config file is) added the include in my index.php file. Nothing worked.

  • Roy

    Thank you!

  • PaulIsLoud

    Hi Piotr, I’ve given your solution a shot, but I’m still seeing 21 blank lines before the xml declaration. Do you have any thoughts on what might be causing it on this site? http://www.drgreene.com/feed/

  • PaulIsLoud

    Hi Piotr, I’ve given your solution a shot, but I’m still seeing 21 blank lines before the xml declaration. Do you have any thoughts on what might be causing it on this site? http://www.drgreene.com/feed/

  • Your solution is really a miracle!!! I didn’t believe my problem can be fixed but you did it! Wasted half a day trying to find blank lines >.<

    Thanks a million!!

  • Manuel

    Yeah…! man, thanks… you are a genius…!

  • Manuel

    Yeah…! man, thanks… you are a genius…!

  • Thanks for this solution.

    It worked for my site http://www.learnabouttheweb.com

    It still works in 2013!

    I have no idea why WordPress is so flaky but I will buy you a beer in Pasadena anytime!

    Cheers!

    • chykalophiagroup

      Hello there! Glad it worked for you. To be honest, even with all the investigation that i’ve done I’m still unable to pin-point a specific cause for this error. Usually it’s an errant character SOMEWHERE in the code … either in a plugin, a theme or even in a post or page.

      It’s truly a wacky issue.

      Glad it worked for you.

  • Vinuta

    thanks , this helped me.
    Vinuta

  • Edward

    Thank you! It finally worked. You are really a genius!

  • Alberto Fortin

    It worked! Thanks!

  • Unfortunately it didn’t work for me but thanks anyway. After much tinkering, re-saving my permalinks settings + clearing my browser cache resolved whatever the issue was. Strange…

    • Hello Sophie,

      Sorry that my fixes didn’t work for you. But I’m very glad you got it working!

      That’s odd though that just resetting the permalinks would fix that!

      Glad it worked!

      Wishing you all the best,
      — Peter

      • caseyctg

        I’d like to add I’m troubleshooting this issue. I did a completely fresh install of WP. I imported my content and did an rss test. All was working. Then I changed my permalink structure and the issue was suddenly back again. I believe there is a larger issue here that somehow relates to the permalink structure. I haven’t solved it, but I can say that from a fresh install the problem didn’t happen until I used the “post name” option in the permalink settings.

        • Hey Casey,

          Thank you very much for this insight. To me this is starting to look less and less like a malfunction and more like conflicting data. For example, if you write a blog post named “About Us” and have a page named “About Us” and use the same permalink structure for posts and pages …. might cause issues. I’ve seen that happen before and it might be what’s causing some data to go awry in the RSS feed. …. maybe.

        • caseyctg

          Thanks for the info, I think I did have a few duplicates when importing…maybe that started my issue. Good insight, I’ll check and let you know what I find!

        • caseyctg

          Ok, I found the issue. It was indeed an issue in my functions.php file. But I believe it was also something being held over from the output cache.

          so my functions.php file was deceiving me because I had a ?> tag at the end of the functions.php file. There was no white space after that tag, which is what was throwing me for a loop.
          However, there was a space after my closing bracket and in between the closing php tag. So my fix was to delete the ending php tag and make sure there were no spaces after the closing bracket.

          I didn’t find this until I read that php files shouldn’t include the closing tag due to this reason:
          If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

        • caseyctg

          Source:

          http://php.net/manual/en/language.basic-syntax.phptags.php

          Also note, I did have to clear my browser cache for the edit to start working.

        • This is great information Casey. Thanks! And it’s awesome to hear you got your issue resolved.

          What baffles me to this day is why on earth does a small little space at the end of a PHP file break everything, especially when PHP is a well make language with well made processors AND PHP is not a tab & space dependent system (one example of those would be Python).

          Glad you got it resolved!

  • Foulsham

    Same as Addison, does not work … 🙁

  • Foulsham

    Greeeaaat ! Sorry it did worked ! I had not refreshed my browsner cache ! Thanks a lot !

  • Awesome man it worked a treat, thanks so much for sharing! 🙂

  • mrrssy

    Worked for me too after clearing browser caches for IE, ctrl+F5 a couple times for Chrome.

  • Pingback: Blank spaces in your Wordpress RSS feed? - Cup Of Coffee()

  • samrand_7

    tnx,it works 🙂

    • Awesome! I’m super glad it worked for you Sam! Let me know if there are any other WP related stuff you’d like solutions to.

  • Vincent

    It works perfectly fine. Thank you !

    • Hey Vincent. I’m glad it worked out for ya! Are there any other WordPress questions you’d like answered?

  • daniel

    Hi
    i uploaded the file in webroot of godaddy hosting and
    i put the following in the index.php file and still no luck 🙁

    what do you suggest???

    • Hello Daniel, that’s a tough question, there are a few things you can try:

      1) make sure it’s in a same directory as the wordpress index.php file ..

      2) For some people the following as worked: clearing wordpress AND browser cache.

      3) disable all plugins. Clear browser cache and WP cache if possible. See if problem persists. If the problem went away, then it was one of the plugins causing the problem. Try re-enabling the plugins one by one.

      4) Try changing themes (temporarily). See if that makes it go away.

      If all that doesn’t work, that means the problem is somewhere in the content of your posts/pages (wherever your feed pulls from). Try going back through your content and see if there are any ‘strange’ characters in there somewhere.

      I wish I could be of more help. hugs

      Let me know if any of the above worked, or not. I’ll try to do some investigation soon and see if I can come up with an updated solution.

  • tnj plt

    wonderfull work and very helpfull, regards

    • Well thank you very much. Those are very kind words. hugs

  • Ah, worked perfectly! Thanks so much for the informative post! I really appreciate you explaining exactly how to do this… what line, etc. Great job. 🙂

  • Muslim

    Worked for us thanks

  • Rahat Bashar

    Hi, this still doesn’t work. However, I tried using feedburner and get this message:

    Error on line 222: The element type “br” must be terminated by the matching end-tag “”

    Do you know what this means?

    Thanks

    • Hey There Rahat,

      What website are you having this trouble on? I’ll take a look.

      The “br must be terminated by a matching end-tag” means that there is some actual formatting issue with your RSS feed. Most likely one of two reasons: a plugin issue (or theme plugin) OR some piece of your content isn’t agreeing well with the RSS feed. It’s one of those two.

      I don’t know how much you know about programming, so I’ll assume nothing for the sake of conversation here. The “br” tag, which looks like this in code: < br / > (minus the spaces after the < and before the >) means it will make a new line of text. Basically, it’s a programming way to place a blank line in text (just like the enter key, except more direct/forceful). The br tag stands by itself usually. Though RSS feeds are generally created using a type of language/method called XML. XML is very very structured where everything has to be rather well described and properly formatted.

      So it telling you that there needs to be an ending br, means that there somewhere is just one < br / > instead of what it wants to see. What it wants to see is something more like usual tagging/code such as: < br > </ br >.

      That’s how must HTML tags work, an opening and a closing one. Though some tags (like the BR tag) can be self closing (< br / >) instead of having a closing tag (such as with a link tag such as this: < a > < / a >).

      Thus, either somewhere in the content of your RSS feed, there is an errant < br / > tag OR some plugin is causing trouble.

  • Quentin

    It works for me ! Thank you a lot a lot a lot and again a lot for this simple solution !

  • Cristian

    Thanks for the fix! it worked

  • Milan

    Million thanks !! Saved my time !!! Thanks !!!!

  • Super glad it worked for you :). If you have any other WordPress questions feel free to drop me a line.

  • Dr Binary

    Hurray! Good news, its working on mozilla, bad news, not working on chrome and safari.

  • Pingback: RSS????????XML declaration????????? | Kimiya Kitani????????()

  • jphogan

    Excellent! Thank you so much for writing this. Worked perfectly.

  • Confirmed working here. Thank you!

  • emilie

    thanks a lot for your work!!!

  • 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

    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

    thank you, is great

  • Josh

    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

    Thank so much it worked for me

  • Niko

    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

    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

    Great!! Tks you very much 🙂

  • Céline

    Thank you so much for your tip !!!

  • AnasAbubackerV

    Yes. it is worked magically.
    Really Thanks.

  • jeff

    thanks for this fix…worked great solved my sitemap issue

  • ALLOFTHEMES.COM

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

  • Pingback: Blog moved to WordPress | Maurizio's blog 3.0()

  • You SIR are a GENIUS!

  • 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

    • Site crashes?! Yikes! That’s not good. I’ll look into this and let you know what I find!

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

  • Fred Reillier

    Didn’t work neither…

  • badri

    You’re a GENIUS !… thank u

  • Fengzi

    Thank you! It’s working!

  • nao

    thx

  • Irfan

    Wow.. it works, thanks a lot

  • Pingback: Income and Traffic Report - November 2013()

  • ejll105

    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

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

  • Pingback: ?? Wordpress RSS ?????? | ????()

  • Awesome tip. Work great for me. Thank You.

  • Romulo

    It works!!! Thanks a lot dude!

  • Anna Cinal

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

  • Exactly as perscribed, thanks doc!

  • Nathusminus

    Thank you so much ! It works for me 🙂

  • Biren

    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

    Unbelievabk´´le, it works 🙂