XML declaration allowed only at the start of the document

samir panchal picture samir panchal · Feb 4, 2013 · Viewed 30k times · Source

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

Answer

Asce4s picture Asce4s · Sep 13, 2019

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