You open /feed/ or /sitemap_index.xml and the browser shows "This page contains the following errors: error on line 2 at column 6: XML declaration allowed only at the start of the document". Feed readers, Mailchimp RSS campaigns and Google Search Console then say the feed or sitemap "could not be read". An XML file must start with <?xml as its very first characters. Something on the site printed a blank line (or a space, or an invisible byte-order mark) before it. The usual source is a theme or plugin file with an empty line before <?php or after a closing ?>. The XML itself is fine; only that stray line has to go.
view-source: in front of it (for example view-source:https://yoursite.com/feed/). If the first line is empty and <?xml sits on line 2, that is the fault.functions.php, wp-config.php, or a plugin. If only a sitemap breaks, look first at the SEO plugin that makes it and anything that hooks into it.functions.php, a hand edit to wp-config.php, or a plugin installed or updated just before the feed broke is the place to start.wp-content/themes/your-theme/functions.php. The very first characters must be <?php, with no blank line or space before them. At the end, delete a closing ?> and any empty lines after it; the file does not need one. Do the same for wp-config.php in the site's main folder.wp-content/plugins/ by adding -off) and reload after each. The one that fixes the feed is the culprit: update it, or replace it.view-source: on the feed again, and confirm <?xml is now on line 1. In Search Console, resubmit the sitemap; in a feed reader, refresh the feed.| What you see | What it means | Usual fix |
|---|---|---|
| "error on line 2 at column 6" | One blank line before <?xml | Remove the empty line before <?php or after ?> in the file that prints it |
| "error on line 1" with odd characters, or nothing visible | A byte-order mark at the start of a PHP file | Re-save the file as UTF-8 without BOM |
| Feed and sitemap both broken | Code that runs on every page prints the line | Check functions.php and wp-config.php, then plugins one by one |
| Only the sitemap broken | The SEO plugin or something hooked into it | Update the SEO plugin, then test the other plugins against it |
| Search Console: "Sitemap could not be read" | Google hit the same stray line | Fix the line, then resubmit the sitemap |
feed-rss2.php. They are not the cause, and an update overwrites them anyway.functions.php with the built-in Theme File Editor if you cannot also reach the host's File Manager: one wrong character there can take the whole site down.Most cases are one blank line or one re-save in one file. If you cannot find which file prints it, that is what the box below is for. Related: "headers already sent" warning, site not showing on Google and PHP warnings on the site.