Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

errors in sitemap.xml due to functions.php #753

Closed
jimlongo56 opened this issue Mar 7, 2016 · 1 comment
Closed

errors in sitemap.xml due to functions.php #753

jimlongo56 opened this issue Mar 7, 2016 · 1 comment

Comments

@jimlongo56
Copy link
Contributor

@olefredrik I just setup Yost SEO on a new site and when I tried to view the sitemap.xml file I was getting the following error I'd never experienced before.

error on line 2 at column 6: XML declaration allowed only at the start of the document

A little googling led to a few threads like the following that all mention you should have no trailing whitespace after the closing php tag in your functions.php file
https://wordpress.org/support/topic/yoast-seo-xml-sitemap-error

I know modern the modern standard is to generally not even have the closing php tag on files, and even after adding one to my functions.php file I was still getting this error.

Then I checked through all the included library files. Some have no closing tags, some have closing tags with trailing whitespace.
I made sure all those files in the library file had a closing php tag ?> and no whitespace or new lines following that tag.

That fixed the error with auto generated sitemap.xml files.

From what I read this is not a Yost SEO issue, but will affect all auto generated wordpress sitemap.xml files. Also note this is a FP5 site.

@olefredrik
Copy link
Owner

Early last month we decided to omit the closing PHP tag at the end of files. According to official PHP documentation, this is considered as best practice.

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

As I see it, this is a Yoast SEO plugin issue and not a FoundationPress issue? I just installed the popular XML Sitemap Generator for WordPress and managed to generate sitemaps without problems.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants