One of the most confusing errors WordPress users face is the XML Parsing Error: XML or text declaration not at start of entity.
This issue usually appears when you open your website’s RSS feed or submit it to a service like FeedBurner or Google News.
While the error looks complicated, it’s most often caused by something surprisingly simple — a blank space before or after PHP tags in your theme or plugin files.
Contact a WordPress developer to get your WordPress issues resolved by a professional.
💡 What Does “XML or Text Declaration Not at Start of Entity” Mean?
When browsers or feed readers parse XML (like your RSS feed), they expect the very first line to be something like:
<?xml version="1.0" encoding="UTF-8"?>
If any space, tab, or invisible character appears before this line, the XML becomes invalid — and you’ll see an error like this:
XML Parsing Error: XML or text declaration not at start of entity
Location: https://example.com/feed/
Line Number 2, Column 1:
This means there’s something outputting content before the XML declaration, breaking the strict formatting XML requires.
⚙️ Common Causes of the XML Parsing Error in WordPress
The most frequent cause is extra whitespace or a blank line in a PHP file.
This can happen before the opening PHP tag <?php or after the closing tag ?>.
🧾 1. Blank Line Before <?php Tag
If a file starts like this:
[blank line here]
<?php
That blank line will be sent to the browser before the XML output, breaking the RSS feed.
🧾 2. Blank Line After ?> Tag
Similarly:
<?php
// some PHP code
?>
That extra space after the closing tag also gets output and corrupts the feed.
🛠️ Step-by-Step Fix for XML Parsing Error in WordPress
Here’s how to troubleshoot and resolve the problem:
🔍 Step 1: Check Your WordPress Theme Files
Inspect the following files in your active theme:
header.phpfooter.phpfunctions.phpsidebar.phpindex.php
Tip: Open each file in a plain-text editor like Visual Studio Code or Notepad++ and enable “Show All Characters” to detect invisible whitespace.
Make sure:
- The first line starts with 
<?phpor<!DOCTYPE html> - There are no spaces or blank lines before or after PHP tags
 
✅ Correct Example:
<?php
// theme header content
?>
<!DOCTYPE html>
<html lang="en">
❌ Incorrect Example:
[blank line]
<?php
// theme header content
?>
<!DOCTYPE html>
🔧 Step 2: Check wp-config.php
Your wp-config.php file is loaded before anything else in WordPress.
Even a tiny blank space here can trigger the “XML or text declaration not at start of entity” error.
Checklist:
- The file should start immediately with 
<?php - There should be no closing 
?>tag — it’s optional and best omitted 
✅ Best Practice:
<?php
define( 'DB_NAME', 'database_name' );
// other settings
🔹 Pro Tip: Never add the closing
?>tag inwp-config.php.
PHP automatically ends the script when the file ends — this prevents accidental whitespace issues.
🧩 Step 3: Review Plugin Files
If the error persists, one of your plugins might be sending unwanted output.
Option A — Deactivate All Plugins
- Go to WordPress Admin → Plugins → Installed Plugins
 - Select all → Deactivate
 
Then check your RSS feed again at:
https://yourdomain.com/feed/
If the feed starts working, one of the plugins is the culprit.
Option B — Rename Plugins Folder
If you can’t access your admin dashboard:
- Connect via FTP or File Manager
 - Rename the folder 
/wp-content/plugins/to/wp-content/plugins-old/ - Visit your RSS feed again
 - If it works, rename the folder back and reactivate plugins one-by-one.
 
🧱 Step 4: Check WordPress Core Feed Files
Rarely, XML feed files inside WordPress core can also be affected, especially if they were manually edited or corrupted.
Check these:
/wp-includes/feed-atom.php/wp-includes/feed-rss2.php
Ensure there are no blank lines before the first PHP tag.
⚠️ Don’t edit these files unless you’re experienced — always back up before modifying WordPress core files.
🧾 Step 5: Validate Your RSS Feed
After making fixes, validate your feed using:
If you still see:
XML or text declaration not at start of entity
go back and recheck for spaces, BOM characters, or invisible tabs before your <?xml or <?php tags.
🧰 Optional: Check for BOM (Byte Order Mark)
Sometimes even if no visible space exists, your file might include a BOM character at the start — usually caused by certain text editors.
To fix:
- Re-save your PHP files in UTF-8 (without BOM) encoding.
 - Editors like VS Code or Notepad++ can do this easily:
- In VS Code: Save with Encoding → UTF-8
 - In Notepad++: Encoding → Convert to UTF-8 (without BOM)
 
 
✅ Final Tips to Prevent XML Parsing Errors
- Never use the 
?>closing tag in PHP-only files. - Avoid editing WordPress files from the dashboard editor — use a proper code editor.
 - Always check your RSS feed after updating your theme or plugins.
 - Keep WordPress and all plugins up to date to avoid file corruption.
 
🧠 Summary: Fixing XML or Text Declaration Error in WordPress
| Cause | Solution | 
|---|---|
Blank space before <?php | Remove the whitespace | 
Blank space after ?> | Remove or avoid closing tag | 
| Extra newline in theme files | Check header.php, footer.php, etc. | 
Whitespace in wp-config.php | Remove closing tag, ensure clean start | 
| Plugin output | Deactivate plugins and test | 
| BOM encoding | Save files in UTF-8 without BOM | 
🔚 Conclusion
The “XML Parsing Error: XML or text declaration not at start of entity” in WordPress might look technical, but it’s almost always caused by a small formatting issue.
By carefully checking your PHP files, removing blank spaces, and avoiding closing tags, you can quickly restore your RSS feed and keep your XML output clean and valid.
