Fix XML declaration RSS feed Error – WordPress – FeedBurner

By Anil Gupta, 2  Tech Tips

Error on line 2 at column 6: XML declaration allowed only at the start of the document is fixed by removing extra blank lines at end of functions.php file.


We recently created a custom theme for our site based on BootStrap and found the Feedburner RSS feed to be non-working during testing.

Interestingly, the wordpress install was working fine except the RSS.

The Problem: XML declaration RSS feed Error

Our Feedburner feed shows the following error:

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 then moved to the real wordpress feed URL (http://www.am22tech.com/feed/) for our blog and that too turned the same error.

RSS feed wordpress XML declaration error

RSS feed wordpress XML declaration error

I then checked in Internet Explorer and found some more information about this bug:

Invalid xml declaration.
 Line: 2 Character: 3

<!--?xml version="1.0" encoding="UTF-8"?-->

Cause of the XML error

Interestingly, if I see the source (Right Click on browser window->View Source), I see that there is a BLANK line on top (the very first line).

RSS feed in wordpress throws XML declaration error - Source view

RSS feed in wordpress throws XML declaration error – Source view

You can see that WordPress did sent the list of articles in RSS feed even though we see the XML declaration error.

This means that the BLANK line at top is primarily hindering the browser’s capability to correctly render this page.

The primary cause is the code that injects the blank line on top of the RSS feed page. This link does provide some insight into how we can troubleshoot. Quick online tips confirms that they were able to fix the problem but with no concrete name of the file to fix.

How I Fixed the problem?

As reported on the above link, the error is primarily due to a blank line just before or after the last PHP tags in a *.php file. Now, the question is which php file?

I found 2 extra BLANK lines at the very end of my theme’s functions.php file:

Functions.php has two extra blank lines at the end of file

Functions.php has two extra blank lines at the end of file

Deleting these lines proves fruitful.

  • If I delete both lines i.e. 171 and 172, the RSS feed starts working fine. The XML declaration error is resolved.
  • If I delete one line i.e. line number 172 from the screen shot (and keep line 171), the RSS feed still works.
  • If I KEEP both lines i.e. 171 and 172, the RSS feed STOPS working. The XML declaration returns.

I tested all other files like comments.php, author.php, index.php etc. by adding 1 or more lines at the end and it did not make any difference. The RSS feed kept working fine.

The only time I was able to reproduce the error was adding more than 1 blank line at the end. i.e. just after the closing ?> tag.

I am sure that 99% of you would be able to solve the issue if you fix your wp-content->theme->functions.php file.

NOTE that you would need to de-activate any caching plug-ins before making the changes (removing extra lines). You can enable it once the problem is resolved.

If that does not solve the issue, you should trouble shoot more to find the error-causing PHP file using the next steps listed below.

Finding and Fixing the error – Other cases

  1. Is it an error in WordPress Core code files?

    I seriously think that you should never place doubt on core files unless you hear other WordPress users also complaining about the same error after a major WordPress update.

    If you have not read about any issue with WordPress, then it must either be your Plug-ins or theme.

  2. Inspect the plugins first or theme?

    To decide between plug-in or custom theme, you can use this simple test instead of de-activating plug-ins one-by-one.

    De-activate current theme and activate the Word-press’s default theme (at this time, it is Twenty Forteen).Now, go and verify the WordPress feed URL (Specific to your blog – http://YOUR_SITE_NAME/feed/).

    If it works with no error, then you rule out any problem with Plug-in files. They are all ok.

    If not, then the problem lies most-probably with a Plug-in. You should start checking them one-by-one in reverse order of their installation.

  3. Theme file has an issue? Fix it.

    If it is theme file, then the biggest suspect should be functions.php file. Try the solution provided above.

    If that does not work, make a back-up copy of current theme’s functions.php file and replace it with the WordPress default theme’s functions.php.
    Now, try to run the feed URL. If it works, then the problem is definitely with your theme’s functions.php.

    If not, look for other PHP files in your theme and remove all blank spaces or extra blank lines at the end of each file. This should fix the issue for you.

Let me know if you need more information.

  • Faisal

    Hello,
    i am new in WordPress and i wanna feed my website with feedburner in order to collect emails for our business and marketing but the problem which i am facing is that when i entered my URL: it says that “the URL does not appear to reference a valid XML file, we encountered the following problem: Error on line 77: the element type “link” must be terminated by the matching tag “/link”. ” can anyone here please help me? i need its solution as soon as it is possible, the problem which i have understood is that i am pasting my link in feed area is therichclique without the “feed”, do i need to change the link or i can just mention it in feedburner URL tab?
    thanks

  • Hi Faisal,

    The feed address for your wordpress blog should be:
    yourWebsiteAddress/feed/

    Note the /feed/ in the path.