Select Page

Fixing the XML declaration allowed only at the start of the document Error in WordPress

by | May 13, 2025 | Security, Troublehsooting

Follow on LinkedIn

I Fix WordPress Websites – Malware Cleanup & Elementor Issues

top rated wordpress

Goal Of the Website

The goal of Kodegems.com is to provide valuable resources, tutorials, and guides for software developers and tech enthusiasts looking to improve their skills and advance their careers. We strive to create a community of learning and growth, where individuals can come to find the information they need to succeed in the tech industry.

Spread the love

If you’re seeing the error “XML declaration allowed only at the start of the document” when opening your sitemap, don’t worry — this is a common WordPress issue and can usually be fixed without touching any code.

What the Error Means

When you visit:

https://yourwebsite.com/sitemap.xml

Instead of seeing your sitemap, you may see:

“XML declaration allowed only at the start of the document.”

This happens because something (like a hidden space or character) is placed before the XML declaration. It can confuse search engines and prevent your site from being properly indexed.

Step-by-Step Fix (No Coding Required)

Step 1: Open Your Sitemap and Confirm the Error

  1. In your browser, go to: https://yourwebsite.com/sitemap.xml
  2. If you see the error instead of your sitemap, continue to the next step.

Step 2: Deactivate All Plugins to Detect Conflicts

  1. Log in to your WordPress Dashboard
  2. Go to Plugins → Installed Plugins
  3. Click Deactivate on all plugins
  4. Refresh your sitemap page

👉 Did the error disappear?

  • Yes? One of the plugins is the culprit → go to Step 3
  • No? Move to Step 4

You can also learn more about plugin conflicts here.

Step 3: Reactivate Plugins One-by-One

  1. Start reactivating plugins one at a time
  2. After each activation, refresh your sitemap
  3. When the error reappears, you’ve identified the problem plugin

What to do next?

  • Deactivate the plugin
  • Contact the plugin developer for support
  • Consider finding an alternative plugin

🎨 Step 4: Switch to a Default WordPress Theme

  1. Go to Appearance → Themes
  2. Activate a default theme like Twenty Twenty-Four
  3. Refresh your sitemap

👉 If the error disappears:

Your theme is the issue. Reach out to the theme developer.

📁 Step 5: Remove Hidden Spaces in Theme File

If your theme is the issue, ask your developer to:

“Check the functions.php file and ensure there are no spaces or blank lines before <?php or after the last line.”

Even one empty space can break the XML formatting.

Step 6: Reset Sitemap Plugin Settings

If you’re using a sitemap plugin like Yoast SEO, Rank Math, or All-in-One SEO, resetting the sitemap settings can help.

For Yoast SEO:

  1. Go to SEO → General → Features
  2. Turn “XML sitemaps” Off → Save
  3. Turn it On again → Save
  4. Refresh the sitemap URL

For Rank Math:

  1. Go to Rank Math → Sitemap Settings
  2. Make a small edit → Click Save Changes
  3. Check your sitemap again

🧑‍💼 Still Need Help?

If you’re not confident doing the steps above, contact your hosting support and say:

“My sitemap is showing an XML declaration error. Can you check for whitespace or output before headers in theme or plugin files?”

Or hire a trusted WordPress developer on Upwork to handle the issue professionally.

Summary Table

Task What to Do
Check sitemap Open yourwebsite.com/sitemap.xml
Deactivate plugins See if any plugin is causing the issue
Switch theme Use a default WordPress theme like Twenty Twenty-Four
Fix functions.php Remove spaces before <?php or after the last line
Reset sitemap plugin Turn sitemap setting Off and On from plugin dashboard

Final Tip

Once the issue is fixed, go to Google Search Console, delete the old sitemap if needed, and resubmit your sitemap to ensure proper indexing.

0
Would love your thoughts, please comment.x
()
x