@brynzovskii Thanks for the suggestion – I’ll update the plugin to include this as an option! Once done (hopefully can get some time this weekend) I’ll reply back here and let you know. 🙂
Hi @brynzovskii, just to update you, I’m using the below code at the moment and it works for sitemaps generated by plugins like Slim SEO (the one I use) but for some reason I haven’t yet figured out, it’s not working for WordPress-generated sitemaps.
/**
* The redirect function.
*/
public function redirect() {
$options = get_option( 'guillotheme_settings' );
if ( $options['skip_sitemap'] !== null ) {
// This should catch anything containing both 'sitemap' and '.xml'
$regex = "/^.*?\bsitemap\b.*?\bxml\b.*?$/";
$req = esc_url( $_SERVER['REQUEST_URI']);
if ( preg_match( $regex, $req ) ) return;
}
if ( ! is_admin() ) {
...
As you can see I’m using a regex to catch any kind of sitemaps (as I figured they all must have ‘sitemap’ and ‘.xml’ in common) and comparing with the request URI using preg_match()
. I didn’t go with str_contains()
as it’s supported only in PHP 8+.
Could you maybe try this code on your site (or a variation of it – ignore the $options['skip_sitemap']
bit) to see if it’s something server-related on my end? If you can’t it’s ok, I’ll try to track down whatever it is that’s going wrong. May not get the time in the next few weeks though as I’ll be away.