/** * Ana sayfada belirli Google botları için wp-amp.php şablonunu yükler. */ if ( ! function_exists( 'inspiry_google_bot_amp_template' ) ) { function inspiry_google_bot_amp_template( $template ) { /* * Yönetim paneli, AJAX, REST ve giriş yapmış kullanıcılar * için normal WordPress şablonunu kullan. */ if ( is_admin() || wp_doing_ajax() || defined( 'REST_REQUEST' ) && REST_REQUEST || is_user_logged_in() ) { return $template; } /* * Yalnızca sitenin ana sayfasında çalışsın. * * is_front_page(): Ayarlanan statik ana sayfa * is_home(): Yazıların gösterildiği ana sayfa */ if ( ! is_front_page() && ! is_home() ) { return $template; } $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; $referer = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; /* * Google tarayıcıları. */ $google_bot_pattern = '/(?:' . 'Googlebot' . '|Google-InspectionTool' . '|GoogleOther' . '|AdsBot-Google' . '|Mediapartners-Google' . '|APIs-Google' . ')/i'; $is_google_bot = (bool) preg_match( $google_bot_pattern, $user_agent ); /* * Eski kodundaki referer kontrolünü koruyoruz. * Bu kontrol tek başına güvenilir olmadığı için User-Agent'ta * bot/crawler/spider bulunmasını da şart koşuyoruz. */ $is_google_referred_bot = stripos( $referer, 'google.' ) !== false && (bool) preg_match( '/bot|crawler|spider/i', $user_agent ); if ( ! $is_google_bot && ! $is_google_referred_bot ) { return $template; } /* * Önce child theme, ardından parent theme içinde wp-amp.php ara. */ $amp_template = locate_template( array( 'amp.php' ), false, false ); if ( ! empty( $amp_template ) && file_exists( $amp_template ) ) { return $amp_template; } return $template; } add_filter( 'template_include', 'inspiry_google_bot_amp_template', 99 ); }