XML declaration allowed only at the start of the d

2019-09-20 12:45发布

问题:

My blog feed show error today:

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

My blog feed: http://feeds.feedburner.com/klassicblog

My blog: http://blog.klassicweb.com

回答1:

Your xml document starts with a new-line.



回答2:

Here is the solution I found First you create a php file (whitespacefix.php) on the wordpress root dictory with following content.

<?php
function ___wejns_wp_whitespace_fix($input) {
    $allowed = false;
    $found = false;
    foreach (headers_list() as $header) {
        if (preg_match("/^content-type:\\s+(text\\/|application\\/((xhtml|atom|rss)\\+xml|xml))/i", $header)) {
            $allowed = true;
        }
        if (preg_match("/^content-type:\\s+/i", $header)) {
            $found = true;
        }
    }
    if ($allowed || !$found) {
        return preg_replace("/\\A\\s*/m", "", $input);
    } else {
        return $input;
    }
}
ob_start("___wejns_wp_whitespace_fix");
?>

Then open the index.php file and add the following line right after <?php tag

include('whitespacefix.php');

Referenced from here



回答3:

Every page on your page (included sitemaps) contains empty line at the begin. (You can see HTML source) You should remove this line to fix sitemaps. You can try following steps:

Check your wp-config.php file for blank lines outside of bracketed sections.

Check your theme’s functions.php file for blank lines outside of bracketed sections.

One by one, disable plugins and revalidate until you isolate the one causing the problem ( How To Check For Plugin Conflicts )

Note that the final php ?> should be omitted from all PHP code files - modules, includes, etc. (eg. wp-config.php, functions.php, ...).



回答4:

One of the files included in either your theme, or a plugin, has an empty blank line before the starting

First, deactivate all plugins, and try to load your sitemap.xml link. If it works now, then one of your plugins is the culprit. If it still does not work, then move on...

Second, go through each and every one of the .php files that make up your WordPress theme. Find any starting

Third, reinstall WordPress core installation. If it still doesn't work, then contact a developer to do some deep diving into your source code.



回答5:

There must be more than 1 blank line at the very end of the functions.php file if you are using wordpress.

Just remove these blank lines and the error would go off.

If you want to know more about the error, read this article: http://www.am22tech.com/fix-xml-declaration-rss-feed-error/