Skip to content

Instantly share code, notes, and snippets.

@dhanar98
Created September 22, 2023 07:51
Show Gist options
  • Save dhanar98/5fa73a20d79d9e86c4a6e600d7942d8d to your computer and use it in GitHub Desktop.
Save dhanar98/5fa73a20d79d9e86c4a6e600d7942d8d to your computer and use it in GitHub Desktop.
WordPress Sitemap Error - Error on line 2 at column 6: XML declaration allowed [FIXED]
<?php
function ___wejns_wp_sitemap_fix($arg) {
$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", "", $arg);
} else {
return $input;
}
}
ob_start("___wejns_wp_sitemap_fix");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment