Jun04
0

XML declaration allowed only at the start of the document

From Complex to Simple Share this post

XML declaration allowed only at the start of the document

When you submit your sitemap sometimes you get this error.

So here is the quick fix to this.

First create whitespace.php in your word press root folder.
Add Below code to that file.

<?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");
?>

Now add below line to index.php right after <? php tag

include('whitespacefix.php');

Done.

Now you can recheck it should be fixed. For reference check the link

If you have any question you can ask in comment section.

About the Author

Avatar

Welcome to our Editor Blog Writer section! Here, you will find informative articles written by our talented team of writers. You can find useful tips for the online business and other knowldgebase content for website, adwords, Wordpress etc. We hope you enjoy reading our articles as much as we enjoy writing them. Happy reading!

Comments are closed.