Table of Contents

Join CloudFly's Telegram channel to receive more offers and never miss any promotions from CloudFly

Hướng dẫn sửa lỗi “XML declaration allowed only at the start of the document” trên Sitemap Wordpress

Sep 23, 2025

Khi truy cập Sitemap của website WordPress đôi khi bạn sẽ gặp lỗi:

XML declaration allowed only at the start of the document

Lỗi này thường xuất hiện do dòng trắng, khoảng trắng hoặc ký tự không hợp lệ xuất hiện trước thẻ <?xml ... ?> trong sitemap.

Bài viết này hướng dẫn bạn xử lý lỗi nhanh trên hosting CloudFly.

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

Đăng nhập vào server qua SSH hoặc File Manager của CloudFly.

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 Sau đó bạn chuột phải vào file vừa tạo và chọn Edit File để mở file và thêm đoạn code sau:

  1. <?php
  2. function ___wejns_wp_whitespace_fix($input) {
  3. $allowed = false;
  4. $found = false;
  5. foreach (headers_list() as $header) {
  6. if (preg_match("/^content-type:\\s+(text\\/|application\\/((xhtml|atom|rss)\\+xml|xml))/i", $header)) {
  7. $allowed = true;
  8. }
  9. if (preg_match("/^content-type:\\s+/i", $header)) {
  10. $found = true;
  11. }
  12. }
  13. if ($allowed || !$found) {
  14. return preg_replace("/\\A\\s*/m", "", $input);
  15. } else {
  16. return $input;
  17. }
  18. }
  19. ob_start("___wejns_wp_whitespace_fix");
  20. ?>

Lưu file lại.

Bước 2: Include file whitespacefix.php vào index.php

Mở file index.php trong thư mục gốc website.

Thêm dòng sau vào đầu file, ngay sau <?php:

include('whitespacefix.php');

Lưu file lại.

Bước 3: Kiểm tra sitemap

Truy cập URL sitemap của website:

Nếu sitemap hiển thị bình thường mà không báo lỗi "XML declaration allowed only at the start of the document", tức là bạn đã xử lý thành công.

Với các bước trên, bạn đã có thể khắc phục triệt để lỗi “XML declaration allowed only at the start of the document” trên sitemap WordPress của mình, giúp website hoạt động ổn định, sitemap hợp lệ và tối ưu SEO trên CloudFly.

👉 Đừng chờ đến khi website tụt hạng mới hành động. Hãy lựa chọn CloudFly ngay hôm nay để:

⚡ Tăng tốc website với LiteSpeed Enterprise.

🔒 An toàn tuyệt đối với tường lửa CSF + anti-DDoS.

🛠 Hỗ trợ kỹ thuật thân thiện – tận tâm – siêu nhanh.

🌐 Đảm bảo SEO mượt mà, không còn lỗi sitemap.

👉 Hãy để CloudFly trở thành đối tác công nghệ đáng tin cậy, giúp website của bạn ổn định – an toàn – bứt phá thứ hạng trên Google.

📩 Liên hệ ngay với chúng tôi để được tư vấn giải pháp phù hợp nhất cho doanh nghiệp của bạn.

CloudFly chúc các bạn thành công!

THÔNG TIN LIÊN HỆ:

HOTLINE: 0904.558.448

WEBSITE: https://cloudfly.vn/

FACEBOOK: https://www.facebook.com/cloudfly.vn

TELEGRAM CHANNELS: https://t.me/cloudflyvn

Share
Event banner 1
Join CloudFly's Telegram channel to receive more offers and never miss any promotions from CloudFly