Conflict With WP Super Cache
-
I noticed a problem when I viewed the sitemap.xml file on some sites. The XML file was displayed without any of the CSS, so it was just an uninterrupted string of all the URLs generated instead of the neatly arranged list I saw on sites where the XML displayed correctly. The oddest thing is that it affected some sites and not others, even though they were running the same theme and plugins. When I tested the site on XML Sitemap Validator, it showed the file was not valid due to “Incorrect http header content-type.” There were no PHP errors or any errors when I enabled WP_DEBUG. There were no visible blank lines at the top of the file when I looked at the source of the sitemap.xml page. If I copied-and-pasted the source into a text document, saved it as a *.xml file, and opened it in Firefox, it displayed correctly.
It turned out the problem was with WP Super Cache. Even when I was logged in and WP Super Cache was not caching the page, on the affected sites, Firefox Developer tools showed that the lines:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="https://thedomain.com/wp-content/plugins/simple-wp-sitemap/css/xml.css"?>
were commented out with HTML comments. I think that WP Super Cache must have been adding some kind of characters to the beginning of the file, but nothing showed up when viewing the source. I verified that I was using exactly the same settings for WP Super Cache on the affected sites as I was on the unaffected sites. I took a look at some other sites using other XML sitemap plugins, and found that this problem isn’t limited to Simple WP Sitemap.
The workaround was to add the sitemap to the list of files not to be cached in WP Super Cache -> Advanced -> “Add here strings (not a filename) that forces a page not to be cached:”
sitemap\.xml
Once I did that, the sitemap.xml displayed correctly.
- The topic ‘Conflict With WP Super Cache’ is closed to new replies.