WordPress Robots Meta Etiketini Kontrol Etme

WordPress sitenizin arama motorlarında nasıl indekslendiğini kontrol etmek, SEO stratejinizin temel taşlarından biridir. Robots meta tag’ı, arama motoru botlarına sayfalarınızın indekslenip indekslenmeyeceğini, takip edilip edilmeyeceğini söyleyen kritik bir HTML elementi olarak çalışır. Ancak çoğu WordPress yöneticisi bu tag’ın gerçekte ne ürettiğini, hangi koşullarda değiştiğini ve nasıl özelleştirileceğini tam olarak bilmez. Bu yazıda functions.php dosyası üzerinden WordPress robots meta tag’ını derinlemesine inceleyeceğiz.

Robots Meta Tag Nedir ve Neden Önemlidir

Robots meta tag’ı, HTML sayfanızın bölümüne eklenen bir direktiftir. Arama motoru botlarına o sayfa için ne yapmaları gerektiğini söyler. robots.txt dosyasından farkı şudur: robots.txt botların sitenize erişimini kontrol ederken, robots meta tag’ı erişim sonrası davranışı belirler.

Temel direktifler şunlardır:

  • index: Sayfayı indeksle
  • noindex: Sayfayı indeksleme
  • follow: Sayfadaki linkleri takip et
  • nofollow: Sayfadaki linkleri takip etme
  • noarchive: Sayfanın önbellek kopyasını gösterme
  • nosnippet: Arama sonuçlarında snippet gösterme
  • noimageindex: Sayfadaki görselleri indeksleme

WordPress, bu tag’ı otomatik olarak yönetir. Ancak “otomatik” derken WordPress’in kendi mantığı çerçevesinde yönetir, her zaman sizin istediğiniz gibi değil. Bu yüzden functions.php üzerinden müdahale etmek çoğu zaman kaçınılmaz hale gelir.

WordPress’in Varsayılan Robots Meta Tag Davranışı

WordPress, robots meta tag’ını oluşturmak için wp_robots filter hook’unu kullanır. WordPress 5.7 sürümünden önce bu işlem wp_head action’ı üzerinden farklı bir yapıyla yapılıyordu. Güncel WordPress sürümlerinde wp_robots_meta_tag() fonksiyonu bu tag’ı üretir.

Varsayılan davranış şöyle işler:

  • Ayarlar > Okuma bölümünde “Arama motorlarının bu siteyi indekslemesini engelle” seçeneği işaretliyse tüm site için noindex üretilir
  • Arama sayfaları (is_search()), sayfalama olan arşiv sayfaları otomatik olarak noindex alabilir
  • Yönetici paneli sayfaları her zaman noindex alır
  • Giriş sayfası (wp-login.php) otomatik olarak noindex alır

Mevcut robots meta tag’ını görmek için en basit yöntem, tarayıcınızda sayfanın kaynak kodunu açıp <meta name="robots" araması yapmaktır. Ama bunu programatik olarak da yapabilirsiniz.

functions.php ile Mevcut Tag’ı Okuma ve Loglama

Önce mevcut robots değerlerini nasıl okuyacağımıza bakalım. Bu işlem için wp_robots filter’ını kullanacağız:

// functions.php'ye ekleyin
add_filter( 'wp_robots', function( $robots ) {
    // Sadece geliştirme ortamında loglama yapalım
    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
        $robots_string = implode( ', ', array_keys( array_filter( $robots ) ) );
        error_log( 'Current URL: ' . $_SERVER['REQUEST_URI'] );
        error_log( 'Robots meta: ' . $robots_string );
    }
    return $robots; // Değiştirmeden geri döndür
} );

Bu kod, WP_DEBUG aktifken her sayfa yüklemesinde robots değerlerini PHP error log’una yazar. wp-content/debug.log dosyasına bakarak hangi sayfada hangi robots değerinin üretildiğini görebilirsiniz.

Daha interaktif bir çözüm için admin bar’a bilgi ekleyebiliriz:

// Admin bar'da robots bilgisini göster
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    if ( is_admin() ) {
        return;
    }

    $robots = apply_filters( 'wp_robots', array() );
    $robots_values = array();

    foreach ( $robots as $directive => $value ) {
        if ( $value === true ) {
            $robots_values[] = $directive;
        } elseif ( is_string( $value ) ) {
            $robots_values[] = $directive . ':' . $value;
        }
    }

    $robots_string = empty( $robots_values ) ? 'Belirtilmemiş' : implode( ', ', $robots_values );

    $wp_admin_bar->add_node( array(
        'id'    => 'robots_meta_info',
        'title' => 'Robots: ' . $robots_string,
        'href'  => '#',
        'meta'  => array(
            'title' => 'Bu sayfanın robots meta tag değeri',
        ),
    ) );
}, 999 );

Bu sayede oturum açmış yöneticiler olarak her sayfada admin bar üzerinde o sayfanın robots değerini anlık görebilirsiniz. Çok işe yarar bir geliştirme aracıdır.

Belirli Sayfa Tiplerine Göre Robots Tag Kontrolü

Gerçek dünya senaryolarında genellikle belirli sayfa tiplerine göre robots değerlerini özelleştirmeniz gerekir. Örneğin bir WooCommerce sitenizde filtreleme parametreli URL’lerin indekslenmesini istemiyorsunuzdur.

add_filter( 'wp_robots', function( $robots ) {

    // URL'de belirli query parametreleri varsa noindex ekle
    $noindex_params = array( 'color', 'size', 'orderby', 'paged', 'min_price', 'max_price' );

    foreach ( $noindex_params as $param ) {
        if ( isset( $_GET[ $param ] ) ) {
            $robots['noindex'] = true;
            $robots['follow']  = true;
            // index varsa kaldır
            unset( $robots['index'] );
            break;
        }
    }

    return $robots;
} );

Sayfa tipine göre daha kapsamlı bir kontrol yapmak istiyorsanız:

add_filter( 'wp_robots', function( $robots ) {

    // Etiket arşivleri - noindex, follow
    if ( is_tag() ) {
        $robots['noindex'] = true;
        $robots['follow']  = true;
        unset( $robots['index'] );
        return $robots;
    }

    // Yazar arşivleri - tek yazarlı sitede gereksiz
    if ( is_author() ) {
        $users = get_users( array( 'role' => 'author', 'number' => 2 ) );
        if ( count( $users ) <= 1 ) {
            $robots['noindex'] = true;
            unset( $robots['index'] );
        }
        return $robots;
    }

    // 404 sayfaları kesinlikle noindex olmalı
    if ( is_404() ) {
        $robots['noindex'] = true;
        unset( $robots['index'] );
        return $robots;
    }

    // Arama sonuçları sayfaları
    if ( is_search() ) {
        $robots['noindex'] = true;
        $robots['follow']  = true;
        unset( $robots['index'] );
        return $robots;
    }

    return $robots;
} );

Özel Post Type ve Taxonomy’ler için Robots Yönetimi

Özel post type veya taxonomy’leriniz varsa bunların robots değerlerini ayrıca yönetmeniz gerekebilir. Örneğin bir portföy sitesinde “proje” post type’ının belirli durumlarını gizlemek isteyebilirsiniz:

add_filter( 'wp_robots', function( $robots ) {

    // Tekil portföy yazısı kontrolü
    if ( is_singular( 'portfolio' ) ) {
        global $post;

        // Custom field ile noindex kontrolü
        $custom_robots = get_post_meta( $post->ID, '_custom_robots', true );

        if ( $custom_robots === 'noindex' ) {
            $robots['noindex'] = true;
            unset( $robots['index'] );
        } elseif ( $custom_robots === 'noindex_nofollow' ) {
            $robots['noindex']  = true;
            $robots['nofollow'] = true;
            unset( $robots['index'] );
            unset( $robots['follow'] );
        }

        // Taslak veya özel durumdaki yazıları noindex yap
        if ( $post->post_status === 'draft' || $post->post_status === 'private' ) {
            $robots['noindex'] = true;
            unset( $robots['index'] );
        }

        return $robots;
    }

    // Özel taxonomy arşivi
    if ( is_tax( 'portfolio_category' ) ) {
        $term = get_queried_object();

        // Boş kategori sayfalarını noindex yap
        if ( $term && $term->count === 0 ) {
            $robots['noindex'] = true;
            unset( $robots['index'] );
        }

        return $robots;
    }

    return $robots;
} );

Robots Meta Tag Değerlerini Veritabanına Kaydetme ve Yönetme

Büyük sitelerde post bazında robots yönetimi için basit bir meta box oluşturabilirsiniz. Bu sayede editörleriniz kod yazmadan robots değerini değiştirebilir:

// Meta box ekle
add_action( 'add_meta_boxes', function() {
    $post_types = get_post_types( array( 'public' => true ), 'names' );
    foreach ( $post_types as $post_type ) {
        add_meta_box(
            'custom_robots_meta_box',
            'Robots Meta Tag',
            'render_robots_meta_box',
            $post_type,
            'side',
            'default'
        );
    }
} );

function render_robots_meta_box( $post ) {
    $value = get_post_meta( $post->ID, '_custom_robots', true );
    wp_nonce_field( 'custom_robots_nonce', 'robots_nonce' );

    $options = array(
        ''                  => 'Varsayılan (Otomatik)',
        'index_follow'      => 'Index, Follow',
        'noindex'           => 'NoIndex, Follow',
        'noindex_nofollow'  => 'NoIndex, NoFollow',
        'index_nofollow'    => 'Index, NoFollow',
        'noarchive'         => 'Index, Follow, NoArchive',
    );

    echo '<select name="custom_robots" style="width:100%">';
    foreach ( $options as $key => $label ) {
        $selected = selected( $value, $key, false );
        echo '<option value="' . esc_attr( $key ) . '" ' . $selected . '>' . esc_html( $label ) . '</option>';
    }
    echo '</select>';
    echo '<p class="description" style="margin-top:8px">Bu sayfanın arama motorlarına nasıl görüneceğini belirler.</p>';
}

// Meta box kaydet
add_action( 'save_post', function( $post_id ) {
    if ( ! isset( $_POST['robots_nonce'] ) ) {
        return;
    }

    if ( ! wp_verify_nonce( $_POST['robots_nonce'], 'custom_robots_nonce' ) ) {
        return;
    }

    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }

    if ( ! current_user_can( 'edit_post', $post_id ) ) {
        return;
    }

    $allowed_values = array( '', 'index_follow', 'noindex', 'noindex_nofollow', 'index_nofollow', 'noarchive' );
    $robots_value   = sanitize_text_field( $_POST['custom_robots'] ?? '' );

    if ( in_array( $robots_value, $allowed_values ) ) {
        update_post_meta( $post_id, '_custom_robots', $robots_value );
    }
} );

Bu meta box’tan kaydedilen değeri robots filter’ına bağlayalım:

add_filter( 'wp_robots', function( $robots ) {
    if ( ! is_singular() ) {
        return $robots;
    }

    global $post;
    $custom_robots = get_post_meta( $post->ID, '_custom_robots', true );

    if ( empty( $custom_robots ) ) {
        return $robots; // Varsayılan davranış
    }

    // Önce mevcut index/follow direktiflerini temizle
    unset( $robots['index'], $robots['noindex'], $robots['follow'], $robots['nofollow'] );

    switch ( $custom_robots ) {
        case 'index_follow':
            $robots['index']  = true;
            $robots['follow'] = true;
            break;

        case 'noindex':
            $robots['noindex'] = true;
            $robots['follow']  = true;
            break;

        case 'noindex_nofollow':
            $robots['noindex']  = true;
            $robots['nofollow'] = true;
            break;

        case 'index_nofollow':
            $robots['index']    = true;
            $robots['nofollow'] = true;
            break;

        case 'noarchive':
            $robots['index']     = true;
            $robots['follow']    = true;
            $robots['noarchive'] = true;
            break;
    }

    return $robots;
} );

WooCommerce Özel Senaryoları

WooCommerce sitelerinde robots yönetimi özellikle kritiktir. Ürün varyasyon URL’leri, filtreleme sayfaları ve hesap sayfaları dikkatli yönetilmelidir:

add_filter( 'wp_robots', function( $robots ) {
    // WooCommerce yüklü değilse devam etme
    if ( ! function_exists( 'is_woocommerce' ) ) {
        return $robots;
    }

    // Sepet sayfası - kesinlikle noindex
    if ( is_cart() ) {
        $robots['noindex'] = true;
        unset( $robots['index'] );
        return $robots;
    }

    // Ödeme sayfası - kesinlikle noindex
    if ( is_checkout() ) {
        $robots['noindex'] = true;
        unset( $robots['index'] );
        return $robots;
    }

    // Hesap sayfaları - noindex
    if ( is_account_page() ) {
        $robots['noindex'] = true;
        unset( $robots['index'] );
        return $robots;
    }

    // Stokta olmayan ürünler için noindex seçeneği
    if ( is_product() ) {
        global $product;
        if ( $product && ! $product->is_in_stock() ) {
            $out_of_stock_noindex = get_option( 'wc_noindex_out_of_stock', 'no' );
            if ( $out_of_stock_noindex === 'yes' ) {
                $robots['noindex'] = true;
                unset( $robots['index'] );
            }
        }
        return $robots;
    }

    // Ürün kategorisi sayfalarında sayfalama kontrolü
    if ( is_product_category() && get_query_var( 'paged' ) > 1 ) {
        $robots['noindex'] = true;
        $robots['follow']  = true;
        unset( $robots['index'] );
        return $robots;
    }

    return $robots;
} );

Robots Tag Varlığını Test Eden Yardımcı Fonksiyon

Hata ayıklama süreçlerini kolaylaştırmak için belirli bir URL’nin robots tag’ını programatik olarak kontrol eden bir yardımcı fonksiyon yazabilirsiniz:

/**
 * Belirli bir post ID için robots meta değerini döndürür
 *
 * @param int $post_id
 * @return string
 */
function get_post_robots_meta( $post_id ) {
    // Geçici olarak global post'u değiştirip filter'ı çalıştır
    $post = get_post( $post_id );

    if ( ! $post ) {
        return 'Post bulunamadı';
    }

    // wp_robots filter'ını simüle et
    $robots = array(
        'index'  => true,
        'follow' => true,
    );

    // Özel post meta'yı kontrol et
    $custom_robots = get_post_meta( $post_id, '_custom_robots', true );

    if ( ! empty( $custom_robots ) ) {
        unset( $robots['index'], $robots['noindex'], $robots['follow'], $robots['nofollow'] );

        switch ( $custom_robots ) {
            case 'noindex':
                $robots['noindex'] = true;
                $robots['follow']  = true;
                break;
            case 'noindex_nofollow':
                $robots['noindex']  = true;
                $robots['nofollow'] = true;
                break;
        }
    }

    $parts = array();
    foreach ( $robots as $directive => $value ) {
        if ( $value === true ) {
            $parts[] = $directive;
        }
    }

    return implode(', ', $parts);
}

// Admin AJAX ile kullanım örneği
add_action( 'wp_ajax_check_post_robots', function() {
    check_ajax_referer( 'check_robots_nonce', 'nonce' );

    if ( ! current_user_can( 'manage_options' ) ) {
        wp_die( 'Yetersiz yetki' );
    }

    $post_id = intval( $_POST['post_id'] ?? 0 );
    $result  = get_post_robots_meta( $post_id );

    wp_send_json_success( array(
        'post_id' => $post_id,
        'robots'  => $result,
    ) );
} );

Toplu Robots Değeri Güncelleme

Bazen sitenizdeki belirli kategorideki tüm yazıların robots değerini toplu güncellemek isteyebilirsiniz. Bunun için bir WP-CLI komutu veya admin action kullanabilirsiniz:

// WP-CLI ile toplu güncelleme
if ( defined( 'WP_CLI' ) && WP_CLI ) {
    WP_CLI::add_command( 'robots bulk-update', function( $args, $assoc_args ) {
        $post_type     = $assoc_args['post-type'] ?? 'post';
        $robots_value  = $assoc_args['value'] ?? '';
        $category_slug = $assoc_args['category'] ?? '';

        $query_args = array(
            'post_type'      => $post_type,
            'posts_per_page' => -1,
            'fields'         => 'ids',
            'post_status'    => 'publish',
        );

        if ( ! empty( $category_slug ) ) {
            $query_args['category_name'] = $category_slug;
        }

        $post_ids = get_posts( $query_args );

        if ( empty( $post_ids ) ) {
            WP_CLI::warning( 'Hiç post bulunamadı.' );
            return;
        }

        $allowed = array( '', 'index_follow', 'noindex', 'noindex_nofollow' );
        if ( ! in_array( $robots_value, $allowed ) ) {
            WP_CLI::error( 'Geçersiz robots değeri. İzin verilenler: ' . implode( ', ', $allowed ) );
            return;
        }

        $progress = WP_CLIUtilsmake_progress_bar( 'Güncelleniyor', count( $post_ids ) );

        foreach ( $post_ids as $post_id ) {
            if ( empty( $robots_value ) ) {
                delete_post_meta( $post_id, '_custom_robots' );
            } else {
                update_post_meta( $post_id, '_custom_robots', $robots_value );
            }
            $progress->tick();
        }

        $progress->finish();
        WP_CLI::success( count( $post_ids ) . ' post güncellendi.' );
    } );
}

Kullanımı şöyle olacaktır:

# Tüm "haberler" kategorisindeki yazıları noindex yap
wp robots bulk-update --post-type=post --category=haberler --value=noindex

# Belirli bir post type'ın robots değerini sıfırla (varsayılana döndür)
wp robots bulk-update --post-type=portfolio --value=""

Yaygın Hatalar ve Dikkat Edilmesi Gerekenler

Robots meta tag yönetiminde sıkça yapılan hatalar şunlardır:

  • wp_robots yerine wp_head kullanmak: WordPress 5.7’den sonra wp_robots filter tercih edilmelidir. Eski yöntemle doğrudan echo ile meta tag basmak hem güvensizdir hem de çakışmalara yol açar.
  • Yanlı öncelik sırası: Birden fazla plugin veya kod parçası robots filter’ı kullanıyorsa öncelik çakışması yaşanabilir. Yüksek öncelik numarası (add_filter( 'wp_robots', 'function', 999 )) son çalışır ve diğerlerini ezer.
  • noindex ve index direktiflerini aynı anda bırakmak: Filter’da hem noindex => true hem de index => true varsa çelişkili bir çıktı oluşur. Birini eklerken diğerini unset ile kaldırmak şarttır.
  • SEO plugin’leriyle çakışma: Yoast SEO, RankMath veya All in One SEO gibi plugin’ler kendi robots yönetimlerini yapar. functions.php ile bu plugin’lerin çıktılarının üstüne yazarken dikkatli olun. Test ortamında önce doğrulayın.
  • Canonical tag ile uyumsuzluk: noindex koyduğunuz bir sayfayı başka bir sayfanın canonical’ı olarak göstermek çelişkilidir. Her iki direktifi birlikte tutarlı yönetin.

Sonuç

WordPress robots meta tag yönetimi, ilk bakışta basit görünse de büyük ve karmaşık sitelerde ciddiye alınması gereken bir konu haline gelir. wp_robots filter hook’u, bu işi temiz ve modüler bir şekilde yapmanızı sağlar. functions.php üzerinden yazdığınız kodlarla sayfa tipine, post meta’ya, query parametrelerine ya da WooCommerce durumuna göre dinamik robots kuralları tanımlayabilirsiniz.

Uygulamada önerim şudur: Önce admin bar yardımcı fonksiyonunu ekleyin ve sitenizi gezin. Hangi sayfaların hangi robots değerini aldığını görün. Sonra meta box sistemini kurun ve editörlerinize sayfa bazında kontrol yetkisi verin. Toplu değişiklikler için WP-CLI komutlarını kullanın. Tüm bunları yaparken SEO plugin’inizle çakışma olup olmadığını staging ortamında test etmeyi unutmayın. Robots meta tag’ı sessiz çalışan ama yanlış yapılandırıldığında sizi Google’ın radarından çıkaran bir direktiftir; buna göre saygı gösterin.

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir