Fix WordPress RSS Feeds XML Parsing Error
In this article
To fix a WordPress RSS feed XML parsing error, you need to identify and remove the invalid content or code that is breaking the feed's XML structure. This guide walks you through the most common causes and provides step-by-step fixes you can apply yourself.
What Causes an XML Parsing Error in WordPress Feeds?
An XML parsing error appears when your RSS feed isn't valid XML. Browsers and feed readers expect a strict format, and any deviation causes them to show an error like “This page contains the following errors” or “XML Parsing Error: not well-formed.” The root cause is almost always stray content that gets output before or after the feed's XML declaration, or within the feed items themselves.
Common culprits include:
- A blank line or whitespace after the closing
?>tag in your theme'sfunctions.phpfile. - Extra output from plugins, especially those that add tracking codes or social sharing scripts.
- Invalid characters in post content, such as raw ampersands or unescaped HTML entities.
- A malformed plugin or theme file that outputs text directly.
How to Diagnose the Exact Error
Before making changes, you need to see the actual error. Open your feed URL (usually yoursite.com/feed/) in a browser. The error message will show a line number and a description of the problem. For example, “error on line 2: mismatched tag” or “error on line 5: xmlParseEntityRef.” This tells you where the invalid content is.
If the error message is not helpful, view the page source (Ctrl+U in most browsers) and look for anything that appears before the first line, which should be <?xml version="1.0" encoding="UTF-8"?>. Any text, spaces, or HTML before that line is a problem. Similarly, check the end of the source for any content after the closing </rss> tag.
Fix 1: Check for Stray Output in Theme Files
The most frequent cause is a blank line or space after the closing PHP tag in your theme's functions.php file. Many WordPress files end with ?>, and if there is a newline or space after that, it gets sent to the browser as output before the XML declaration.
- Go to Appearance → Theme File Editor in your WordPress dashboard.
- Open
functions.php. - Look at the very end of the file. If you see
?>, delete it and any whitespace after it. It's safe to remove the closing PHP tag entirely—PHP files don't need it, and this prevents accidental whitespace output. - Save the file and check your feed again.
If the error persists, check other theme files that might output content, such as header.php or footer.php. Look for any echo statements or HTML outside PHP blocks that shouldn't be there.
Fix 2: Disable Plugins to Find the Culprit
Plugins are a common source of invalid output. A plugin might be adding a script or a comment that breaks the XML. To test, temporarily deactivate all plugins:
- Go to Plugins → Installed Plugins.
- Select all plugins and choose Deactivate from the bulk actions dropdown.
- Check your feed. If it works, reactivate plugins one by one, checking the feed after each activation until the error returns. That plugin is the cause.
If you can't access the dashboard, you can rename the plugins folder via FTP or your hosting file manager. Rename it to plugins_old to disable all plugins, then check the feed. If it works, rename it back and proceed with the one-by-one method.
Fix 3: Clean Up Post Content
Sometimes the error is in a specific post. The feed includes the full content or excerpt, and if a post contains raw ampersands (&), unescaped HTML, or broken tags, it can break the XML. Use the error message's line number to identify which post might be causing it (though line numbers in the feed don't directly map to posts, you can approximate by looking at the content around that line).
To fix:
- Edit the post and check for stray
&characters. Replace them with&if they are meant to be displayed as ampersands. - Look for unclosed HTML tags like
<div>without a closing</div>. - If you use a page builder or custom code, ensure it outputs valid HTML.
Fix 4: Use a Feed Validation Tool
After making changes, use the W3C Feed Validation Service (validator.w3.org/feed) to check your feed. It will show you any remaining errors and help you pinpoint the exact line. This is especially useful if the browser error is vague.
Simply enter your feed URL and click “Validate.” The tool will list errors and warnings with line numbers. Fix those and re-validate until you get a green “This is a valid RSS feed” message.
Frequently Asked Questions
Why does my feed work sometimes but not others?
This often happens when a post with invalid content is published, or when a plugin update introduces a bug. The feed is generated dynamically, so any change to content or code can break it. If it's intermittent, check the most recent posts and any plugins you've recently updated.
Can I use a plugin to fix the feed?
Yes, there are plugins like “RSS Feed Fixer” that try to clean up output, but they are not a permanent solution. It's better to find and fix the root cause, as plugins can slow down your site or conflict with other plugins.
Will this affect my site's SEO?
Yes, a broken feed can affect your site's visibility in search engines and reduce the effectiveness of your content syndication. Search engines may see the feed as a sign of poor site health, and feed readers will stop updating your content. Fixing it promptly is important.
What if I can't access the WordPress dashboard?
If you're locked out, use FTP or your hosting file manager to access the files. You can rename the plugins folder to disable all plugins, or edit the theme files directly. This is also useful if the error is preventing the dashboard from loading.
Is it safe to remove the closing PHP tag?
Yes, it's a best practice in WordPress development. The closing tag is optional, and removing it prevents accidental whitespace output. This is a standard recommendation from WordPress coding standards.
How do I prevent this from happening again?
Always use a child theme for customizations, keep plugins updated, and avoid adding custom code directly to your theme's files unless you know what you're doing. Regularly validate your feed after making changes to your site.