Error on Line 2 at Column 6 Declaration Sitemap Error Fix: WordPress

sitemap

A sitemap is important to every website because here you provide information about pages, media, and files on your site, and search engine crawlers crawl that information from the sitemap. What if you created your WordPress website you select the theme did every change which gives your site a different and attractive look and finds out the sitemap is not working. Most of the time it happens it’s a common WordPress error but no worry every problem has a solution.

If you also facing this “error on line 2 at column 6: XML declaration allowed only at the start of the document” error then don’t worry by following few steps your problem will be resolved. Basically, it happens when a plugin or theme works incorrectly and adds a white space at the top or bottom of the sitemap. Let’s start and resolve this sitemap error with some troubleshooting steps.

Remove White Spaces Manually

First, check it out that if there is any white space in the “function.php” file. Here are steps where you find this file “Login to WordPress account -> Appearance -> Theme Editor -> Theme Functions (function.php)”.

Then on top before <?php and at the bottom after .php’; check if there is any white space if you find any then remove it and reload the sitemap page it will start working if not then there are other methods mention below.

Use a Code

Login to Cpanel, when you purchase hosting you will get the Cpanel. After login into Cpanel go to file manager-> wp-config.php and check there is any white space at the top and bottom and remove it. If not then create a file “whitespacefix.php” and add the below code in it.

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

After adding this code in “whitspacefix.php” open the file index.phn and add the line include(‘whitespacefix.php’); from the top after the <?php tag. Refresh your sitemap page and here you go its starts working.

If you don’t want to do all these steps then do one thing change your theme to the default WordPress theme which was at the start and then check after that the sitemap starts working or not if yes then there is a problem in the theme which you can resolve by the upper steps or just change the theme with a new theme. Another step is to deactivate your all plugins and activate it one by one and check if the sitemap starts working it’s a time taken one but sometimes it works.

Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
2
0
Would love your thoughts, please comment.x
()
x