Created
September 22, 2023 07:51
-
-
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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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