// ====================================================================
// === کدهای نهایی سئوی فیلترها - مقابله مستقیم با Rank Math/Core WP ===
// ====================================================================
// ۱. تابع تشخیص صفحه فیلترشده (ایمن و مستقل)
if ( ! function_exists( 'ag_is_filtered_woo_catalog' ) ) {
function ag_is_filtered_woo_catalog() {
if ( ! function_exists( 'is_shop' ) || ! ( is_shop() || is_post_type_archive( 'product' ) || is_product_taxonomy() ) ) {
return false;
}
// بررسی Filter Everything
if ( function_exists( 'wpc_filter_is_filtered_page' ) && @wpc_filter_is_filtered_page() === true ) {
return true;
}
// بررسی URI/GET
$uri = isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : '';
$qs = ( isset( $_GET ) && is_array( $_GET ) ) ? array_keys( $_GET ) : array();
if ( stripos( $uri, '/filter/' ) !== false || stripos( $uri, '/filters/' ) !== false ) {
return true;
}
foreach ( $qs as $k ) {
if ( preg_match( '/^(filter_|fe_|pa_|attribute_|min_price|max_price|rating_filter|orderby|on_sale|in_stock|product_cat)$/i', (string) $k ) ) {
return true;
}
}
return false;
}
}
/**
* ۲. اعمال noindex, follow به صورت مستقیم روی هسته وردپرس و Rank Math
* اولویت: ۹۹۹ برای غلبه بر تنظیمات افزونهها
*/
add_filter( 'wp_robots', 'ag_force_robots_on_filtered_pages', 999 );
add_filter( 'rank_math/frontend/robots', 'ag_force_robots_on_filtered_pages', 999 );
if ( ! function_exists( 'ag_force_robots_on_filtered_pages' ) ) {
function ag_force_robots_on_filtered_pages( $robots ) {
if ( ag_is_filtered_woo_catalog() ) {
// اجبار noindex
$robots['noindex'] = true;
unset( $robots['index'] );
// اجبار follow
$robots['follow'] = true;
unset( $robots['nofollow'] );
// برای Rank Math: حذف فیلتر nofollow از لینکها
if ( function_exists( 'remove_action' ) && class_exists( '\RankMath\Frontend\Clean_Links' ) ) {
remove_filter( 'wp_kses_allowed_html', array( \RankMath\Frontend\Clean_Links::get(), 'add_rel_nofollow_to_links' ), 10 );
}
}
return $robots;
}
}
/**
* ۳. اعمال Canonical به /shop/ (برای همه افزونههای سئو و هسته)
* اولویت: ۹۹۹ برای جایگزینی Canonical پیشفرض افزونهها در صفحات فیلترشده
*/
add_filter( 'rank_math/frontend/canonical', 'ag_force_canonical_for_filters', 999 );
add_action( 'wp_head', 'ag_force_canonical_for_filters_wp_head', 1 );
if ( ! function_exists( 'ag_force_canonical_for_filters' ) ) {
function ag_force_canonical_for_filters( $canonical ) {
if ( ag_is_filtered_woo_catalog() ) {
return get_permalink( wc_get_page_id( 'shop' ) );
}
return $canonical;
}
}
// تابع پشتیبان برای تزریق Canonical در wp_head (اگر افزونه سئو وجود نداشت)
if ( ! function_exists( 'ag_force_canonical_for_filters_wp_head' ) ) {
function ag_force_canonical_for_filters_wp_head() {
if ( ag_is_filtered_woo_catalog() ) {
// فقط اگر هیچ تگ Canonical دیگری در صفحه نباشد، این تگ را اضافه میکند.
// اگر افزونه سئو فعال باشد، فیلتر بالا (rank_math/frontend/canonical) این کار را انجام میدهد.
if ( ! has_filter( 'rank_math/frontend/canonical' ) && ! has_filter( 'wpseo_canonical' ) ) {
$shop_url = get_permalink( wc_get_page_id( 'shop' ) );
echo '' . PHP_EOL;
}
}
}
}
/**
* ۴. نهایی کردن follow با حذف rel="nofollow" از محتوای HTML
* این تنها راهی است که در صورت شکست همه روشهای بالا، follow بودن تضمین شود.
*/
add_action( 'template_redirect', 'ag_finalize_follow_links', 9999 );
if ( ! function_exists( 'ag_finalize_follow_links' ) ) {
function ag_finalize_follow_links() {
if ( ag_is_filtered_woo_catalog() ) {
ob_start( function( $buffer ) {
// حذف تمام rel="nofollow" از تگهای در HTML نهایی
return preg_replace( '/(]*)\s+rel=["\']nofollow["\']/i', '$1', $buffer );
});
}
}
}
// ====================================================================
// === پایان کدهای سفارشی ===
// ====================================================================
https://arad-gostar.com/page-sitemap.xml
2025-10-28T09:51:20+00:00
https://arad-gostar.com/video-sitemap.xml
2025-10-27T22:03:43+00:00