XML declaration allowed only at the start of the document XML declaration allowed only at the start of the document wordpress wordpress

XML declaration allowed only at the start of the document


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

<?phpfunction ___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


Your xml document starts with a new-line.


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