From 42f8a380a0174a2f35024e8a4c6ab301ca53a0ad Mon Sep 17 00:00:00 2001 From: "Anton.AE" Date: Sun, 5 Jul 2026 14:18:59 +0300 Subject: [PATCH] sitemap --- .../sevastopol-tort-child/inc/routes.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/wp-content/themes/sevastopol-tort-child/inc/routes.php b/wp-content/themes/sevastopol-tort-child/inc/routes.php index 04ac2e9..7c2f783 100644 --- a/wp-content/themes/sevastopol-tort-child/inc/routes.php +++ b/wp-content/themes/sevastopol-tort-child/inc/routes.php @@ -17,8 +17,23 @@ function sev_tort_query_vars( $vars ) { return $vars; } -add_action( 'template_redirect', 'sev_tort_static_seo_files', 0 ); +add_filter( 'wp_sitemaps_enabled', '__return_false' ); + +add_filter( 'redirect_canonical', 'sev_tort_disable_static_seo_redirects', 10, 2 ); +function sev_tort_disable_static_seo_redirects( $redirect_url, $requested_url ) { + if ( sev_tort_is_static_seo_path() ) { + return false; + } + + return $redirect_url; +} + +add_action( 'init', 'sev_tort_static_seo_files', 0 ); function sev_tort_static_seo_files() { + if ( ! sev_tort_is_static_seo_path() ) { + return; + } + $path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : ''; $path = trim( (string) $path, '/' ); @@ -35,6 +50,13 @@ function sev_tort_static_seo_files() { } } +function sev_tort_is_static_seo_path() { + $path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : ''; + $path = trim( (string) $path, '/' ); + + return in_array( $path, array( 'sitemap.xml', 'sitemap_index.xml', 'robots.txt' ), true ); +} + function sev_tort_send_sitemap_index() { status_header( 200 ); header( 'Content-Type: application/xml; charset=UTF-8' );