XML declaration allowed only at the start of the document

后端 未结 5 524
陌清茗
陌清茗 2021-01-14 10:08

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 s

相关标签:
5条回答
  • 2021-01-14 10:16

    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/

    0 讨论(0)
  • 2021-01-14 10:16

    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.

    0 讨论(0)
  • 2021-01-14 10:23

    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, ...).

    0 讨论(0)
  • 2021-01-14 10:34

    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

    0 讨论(0)
  • 2021-01-14 10:42

    Your xml document starts with a new-line.

    0 讨论(0)
提交回复
热议问题