Contents
- 1 What the Error Means
- 2 Step-by-Step Fix (No Coding Required)
- 2.1 Step 1: Open Your Sitemap and Confirm the Error
- 2.2 Step 2: Deactivate All Plugins to Detect Conflicts
- 2.3 Step 3: Reactivate Plugins One-by-One
- 2.4 🎨 Step 4: Switch to a Default WordPress Theme
- 2.5 📁 Step 5: Remove Hidden Spaces in Theme File
- 2.6 Step 6: Reset Sitemap Plugin Settings
- 2.7 🧑💼 Still Need Help?
- 3 Summary Table
- 4 Final Tip
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
- In your browser, go to:
https://yourwebsite.com/sitemap.xml
- If you see the error instead of your sitemap, continue to the next step.
Step 2: Deactivate All Plugins to Detect Conflicts
- Log in to your WordPress Dashboard
- Go to Plugins → Installed Plugins
- Click Deactivate on all plugins
- 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
- Start reactivating plugins one at a time
- After each activation, refresh your sitemap
- 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
- Go to Appearance → Themes
- Activate a default theme like Twenty Twenty-Four
- 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:
- Go to SEO → General → Features
- Turn “XML sitemaps” Off → Save
- Turn it On again → Save
- Refresh the sitemap URL
For Rank Math:
- Go to Rank Math → Sitemap Settings
- Make a small edit → Click Save Changes
- 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.
I Design and Develop SEO optimized Websites that help Businesses and E-commerce stores to generate 5X more REVENUE ⭐ Designed 500+ Websites || WordPress Developer || Web Designer 🏆 Top Rated On UPWORK