Lỗi gặp khi load sitemap của Yoast SEO hay Rankmath
This page contains the following errors: error on line 2 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.
Bước 01: Tạo file PHP và đặt trong thư mục root của web, đặt tên tùy chọn, ví dụ sitemap.php
Nội dung trong file:
<?php
function flatdev_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("flatdev_wp_whitespace_fix");
Include vào file index.php
include('sitemap.php');
Vấn đề đã được giải quyết!









