W3TC and Google XML Sitemaps – XML declaration error
-
Hello,
Recently, when switched to PHP 7.4 (Nginx, php-fpm) on WordPress 5.5.3 with latest version of W3 Total Cache and Google XML Sitemaps plugin I have encountered error:
This page contains the following errors: error on line 2 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.
The problem was, the sitemap was somehow included in “cache”, so it was re-generated on new post published.
But, the generated “cached” version of sitemap.xml has had the 1st line empty and then the <xml> tag on the 2nd line.The options I have had enabled were:
– pgcache_accept_uri (I have had here the stated for sitemap)
– pgcache__cache__nginx_handle_xml (Was and still is checked)After I have successfully searched and modified few .php files – nothing changes, the error still persisted.
After on, I have found out the W# Total cache HTML comment tag at the end and asked myself maybe the cache is the problem?
So, went back to the W3 Total Cache and added the following code:
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)? ([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml
Under the fields for Page Cache and Browser Cache:
– pgcache_reject_uri
– browsercache_no404wp_exceptionsSo, at the end:
– pgcache_reject_uri and browsercache_no404wp_exceptions (+ added and contains: `[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*?)sitemap([a-z0-9_\-]*)?\.xml`)
– pgcache_accept_uri (now it is empty)
– pgcache__cache__nginx_handle_xml (it is checked)The sitemap loads correctly, no error, regarding the “cache” HTML comment is still visible on the last line.
But, the first line of the sitemap document is the starting point as is <?xml …>, which before was “empty” and the strange error occured.
The sitemap was not indexed by Google News for 5 days since the switch to PHP 7.4.
I have all PHP extensions enabled and installed, so, hm … maybe the W3TC or the Google XML Sitemaps?
Because, in the meanwhile before changing the options in W3TC, I have also “just in case” went through and again “cleared” alrwady “cleared” white spaces and lines in /web/ folder of default WordPress “wp-*.php” files.
Restarted PHP 2-3 times, but nothing happened, cleared the Page Cache, but the error was still there.So, after that I found out the “cace comment” on the bottom of the sitemap URI/file, wen to the W3TC Options and made the stated changes to not cache sitemap or exclude from.
The error still persits on my custom-page for Google News Publisher:
– https://www.racunalo.com/googlenewsfeed/I have also added the “googlenewsfeed/” (without quotes) to the same fields, but the error still remains on the https://www.racunalo.com/googlenewsfeed/ – my PHP script to generate feed by guidelines for Google News Publisher.
But, not anymore on the https://www.racunalo.com/sitemap.xml – generated by Google XML Sitemaps plugin.
Also, no error on https://www.racunalo.com/feed/ – WordPress RSS default feed.
The page I need help with: [log in to see the link]
- The topic ‘W3TC and Google XML Sitemaps – XML declaration error’ is closed to new replies.