Khi truy cập Sitemap của website https://domain.com/sitemap_index.xml và gặp lỗi (error on line 3 at column 6), (error on line 2 at column 6), (error on line 4 at column 6)… Để xử lý lỗi này, bạn có thể làm theo các bước hướng dẫn của Htdigi dưới đây.

Fix Loi Xml Declaration Allowed Only At The Start Of The Document

Bước 1: Tạo file whitespacefix.php

Đầu tiên, bạn hãy đăng nhập vào Hosting/VPS của bạn. Tiếp đó, bạn di chuyển vào đúng đường dẫn chứa dữ liệu website và tạo mới một File mới và đặt tên là whitespacefix.php

CleanShot 2024 01 09 at 19.39.31

Tiếp đó bạn chuột phải vào file vừa tạo và chọn Edit File,

CleanShot 2024 01 09 at 19.40.45

Và thêm đoạn code bên dưới vào.

<?php
function ___wejns_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("/As*/m", "", $input);
    } else {
        return $input;
    }
}
ob_start("___wejns_wp_whitespace_fix");
?>
CleanShot 2024 01 09 at 19.42.11
Thêm code xong bạn hãy Save lại.

Bước 2:  Include vào config.php

Bây giờ, các bạn chỉ cần mở File config.php của website, và include file vừa tạo ở Bước 1 vào là xong.

Tiếp đó thêm đoạn bên dưới vào:

include('whitespacefix.php');
Fix Loi Xml Declaration Allowed Only At The Start Of The Document 2
Fix Loi Xml Declaration Allowed Only At The Start Of The Document 2

Sau khi làm xong, hãy truy cập Sitemap của website theo liên kết https://domain.com/sitemap_index.xml để kiểm tra kết quả. Nếu Sitemap hiển thị như bên dưới là bạn đã xử lý thành công rồi nhé.

Fix Loi Xml Declaration Allowed Only At The Start Of The Document 3

Htdigi chúc các bạn thực hiện thành công.!

Messenger
Messenger
Zalo
Chat Zalo
Messenger
Zalo