How to exclude xml File from caching
-
Hi there,
how can we exclude e.g. sitemap_index.xml from caching?
-
Hi @mapdi
can you please add from which plugin this sitemap is coming?
We already skip the cache for the core sitemaps:
https://github.com/pluginkollektiv/cachify/issues/242
https://github.com/pluginkollektiv/cachify/pull/254For skipping the sitemap caching for the Google XML Sitemaps plugin you can use our filter
cachify_skip_cacheas seen here:
https://github.com/pluginkollektiv/cachify/issues/60#issuecomment-335106482If we know which plugin is generating this Sitemap we will find a way to skip it with the before mentioned method.
All the best
TorstenHi @zodiac1978
Thank you.
We use the Rank Math plugin to create the sitemap xml file. https://wordpress.org/plugins/seo-by-rank-math/
So if I understand this correctly I would have to exclude the xml file (sitemap_index.xml) via hook?
/* * Cachify: Do note cache XML Sitemap Rank Math */ if (defined('CACHIFY_FILE')) { add_filter( 'cachify_skip_cache', function() { global $wp_query; return !empty($wp_query->query_vars["sitemap_index"]); } ); }Best regards
mapdiHi @mapdi
we need to check for the correct
query_var.For Google XML Sitemap this is defined here:
https://github.com/Auctollo/google-sitemap-generator/blob/dbca6fc9b9dd8cd0cd9e63758650d3f727d99683/class-googlesitemapgeneratorloader.php#L104-L114And the rewrite rules are defined after that.
Now we need to look which
query_varRankMath is using. Looks like this is defined here:
https://github.com/rankmath/seo-by-rank-math/blob/eea089f0afe7f476d1f9dadc1a9f75377373d282/includes/modules/sitemap/class-router.php#L40-L54So I would try one of those three
query_vars. Maybesitemap_n:/* * Cachify: Do note cache XML Sitemap Rank Math */ if (defined('CACHIFY_FILE')) { add_filter( 'cachify_skip_cache', function() { global $wp_query; return !empty($wp_query->query_vars["sitemap_n"]); } ); }Can you please try this and report back if this works?
Thanks in advance!
All the best
TorstenThank you very much.
At the moment it seems to work. But I will report here as soon as it doesn’t work properly anymore.
With kind regards!
The topic ‘How to exclude xml File from caching’ is closed to new replies.