Skip to content

Instantly share code, notes, and snippets.

@vandanojan
Created December 27, 2024 18:09
Show Gist options
  • Save vandanojan/20443d2d03e379403364c45c13fd872a to your computer and use it in GitHub Desktop.
Save vandanojan/20443d2d03e379403364c45c13fd872a to your computer and use it in GitHub Desktop.
<?php
function fix_wp_sitemap_whitespace($input) {
$allowed = false;
$found = false;
foreach (headers_list() as $header) {
if (preg_match("/^content-type:\s+(text\/(html|application\/(xhtml\+xml|atom\+xml|xml)))/i", $header)) {
$allowed = true;
}
if (preg_match("/^content-type:\s+/i", $header)) {
$found = true;
}
}
if ($allowed || $found) {
return preg_replace("/^\s*/m", "", $input);
} else {
return $input;
}
}
ob_start("fix_wp_sitemap_whitespace");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment