Fix lỗi Render Sitemap

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!

Về tôi

Minh Anh

Xin chia sẻ những phần việc nhỏ ở các dự án đã triển khai để tiện sử dụng lại ở những dự án khác, giúp rút ngắn thời gian hoàn thành sản phẩm, giảm chi phí cho đối tác và khách hàng.

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Danh mục bài viết

Khám phá những nội dung mới nhất