How to fix Sitemap error? 2023

What is Sitemap?

A sitemap is a file that lists all the pages of a website and provides information about each page’s content and structure to search engines. The sitemap helps search engines crawl the website more efficiently and effectively and can also improve the website’s search engine optimization (SEO).

Sitemaps are typically written in XML format and are submitted to search engines through their webmaster tools. They can include information such as the frequency with which pages are updated, the priority of pages, and alternative language versions of a page.

Having a sitemap is important for websites, especially large websites with a lot of pages, as it makes it easier for search engines to discover and index all of the website’s pages, which can improve the website’s visibility in search results.

How to fix Sitemap error?

In this article I will tell you how you can fix “This page contains the following errors: error on line 3 at column 7 : XML declaration allowed only at the start of the document. Below is a rendering of the page up to the first error.”

Sitemap Error

To fix this error you need to follow the steps given below:

  1. Open a new file in notepad or any other editor.
  2. Paste the code given below in the file and save the file as sitemapfix.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;
  1. Now open the WP panel of your website. (like this :
  2. Then click on WP File Manager plugin
  3. Now paste the sitemapfix.php file under public_html
  4. Now open the index.php file and insert the code given below after <?php
  1. Now click on save & close.

And done the sitemap error has been fixed. Basically the code above removes the blank spaces and blank lines in the theme.

What causes this error?

This error is caused by the blank line (whitespace) or any space before declaration of XML DOCTYPE. And this space or blank line is caused by plugins like Litespeed cache plugin or Autoptimze plugin.


Sitemap error

As you can see in our case when we see the source code of Sitemap.xml page then you can see a blank space and some blank lines before the start of XML tag (<?).


So I hope I was able to fix this sitemap error. If you are having any kind of issue regarding sitemap then you can contact us at

The video on this problem is coming soon on our YouTube channel. In the mean time you can subscribe our channel. Thank YOU

Leave a Reply

Your email address will not be published. Required fields are marked *