Mevcut kategorilerimde gereksiz bölümler vardı. Title kısmını aşağıda ki gibi düzenleyip, mevcut kategori açıklamasını Yoast Kategori açıklama kısmına kopyalıyor. Çok fazla siteniz ve kategoriniz varsa bu eklenti işinizi görür. Sadece fayfalı bir paylaşım olması için yardım maksatlı paylaşılmıştır.
Yoast Category Updater, kategori açıklamalarını otomatik olarak Yoast SEO meta açıklamasına kopyalar ve kategori başlığını tek seferde şu şablona ayarlar: %%term_title%% %%page%% %%sep%% %%sitename%%. Kısacası, kategori sayfalarınızın SEO başlık ve açıklamalarını toplu halde, güvenli ve hızlı biçimde düzenlemenizi sağlar.
Öne çıkanlar
- Toplu işlem: Seçtiğiniz kategorileri tek tıkla günceller
- Doğru kayıt: Değerleri Yoastın kullandığı wpseo_taxonomy_meta alanına yazar
- Güvenli: Yetki ve nonce kontrolüyle yönetici panelinden çalışır
- Esnek: Açıklama boşsa mevcut değeri korur, başlık şablonunu yine uygular
- Hafif ve ücretsiz: Kur, seç, güncelle
- Eklentiyi yükleyip etkinleştirin
- Yönetim menüsünden Yoast Kategori Güncelleme sayfasına gidin
- Kategorileri işaretleyin ve Seçilenleri Güncelle düğmesine basın
Yoastın Indexables yapısı kullanan sitelerde, değişiklikler kısa sürede yansır. Gerekirse Yoast → Tools → SEO data optimization çalıştırabilirsiniz.
<?php
/*
Plugin Name: Yoast Category Updater
Description: Kategori açıklamasını Yoast SEO meta açıklamasına kopyalar ve başlığı %%term_title%% %%page%% %%sep%% %%sitename%% olarak ayarlar. Güncellemeden sonra Yoast indexable'ı yeniden inşa eder, WP edit kancalarını tetikler ve bilinen cache'leri temizler.
Version: 1.4
Author: Beytullah
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* Admin menü.
*/
add_action( 'admin_menu', function () {
add_menu_page(
'Yoast Kategori Güncelleme',
'Yoast Kategori Güncelleme',
'manage_options',
'yoast-category-updater',
'ycu_admin_page',
'dashicons-update'
);
} );
/**
* Yoast indexable'ı güvenli şekilde yeniden inşa eder (v14+).
*/
function ycu_rebuild_yoast_indexable_for_term( $term_id, $taxonomy ) {
try {
if ( function_exists( 'clean_term_cache' ) ) {
clean_term_cache( (int) $term_id, $taxonomy );
}
if ( function_exists( 'YoastSEO' ) && method_exists( YoastSEO(), 'classes' ) ) {
$container = YoastSEO()->classes;
// Modern yol: Indexable_Term_Action
if ( class_exists( '\Yoast\WP\SEO\Actions\Indexable\Indexable_Term_Action' ) ) {
$action = $container->get( \Yoast\WP\SEO\Actions\Indexable\Indexable_Term_Action::class );
if ( $action && method_exists( $action, 'build_for_term' ) ) {
$action->build_for_term( (int) $term_id, $taxonomy );
}
}
// Daha eski sürümler
elseif ( class_exists( '\Yoast\WP\SEO\Builders\Indexable_Term_Builder' ) ) {
$builder = $container->get( \Yoast\WP\SEO\Builders\Indexable_Term_Builder::class );
if ( $builder && method_exists( $builder, 'build_for_term' ) ) {
$builder->build_for_term( (int) $term_id, $taxonomy );
}
elseif ( $builder && method_exists( $builder, 'build' ) ) {
$builder->build( (int) $term_id, $taxonomy );
}
}
// Yoast cache helper
if ( class_exists( '\Yoast\WP\SEO\Helpers\Cache_Helper' ) ) {
$cache = $container->get( \Yoast\WP\SEO\Helpers\Cache_Helper::class );
if ( $cache && method_exists( $cache, 'clear' ) ) {
$cache->clear();
}
}
}
} catch ( \Throwable $e ) {
// Sessiz geç.
}
}
/**
* WP çekirdek "edited_term" zincirini tetiklemek için no-op update.
* (Panelde "Güncelle"ye basınca olanı taklit eder.)
*/
function ycu_trigger_wp_edit_hooks( $term_id, $taxonomy ) {
$term = get_term( $term_id, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$args = [
// Aynı değerlerle güncelliyoruz; amaç kancaların tetiklenmesi.
'name' => $term->name,
'slug' => $term->slug,
'description' => $term->description, // HTML saklı
];
$result = wp_update_term( $term_id, $taxonomy, $args );
// Hata olsa bile önemli değil; kancalar çoğu zaman tetiklenir.
}
}
/**
* Bilinen cache eklentileri için URL purge denemeleri (zararsız).
*/
function ycu_purge_caches_for_url( $url ) {
// WP Rocket
if ( function_exists( 'rocket_clean_files' ) ) {
@rocket_clean_files( $url );
}
// LiteSpeed Cache
if ( function_exists( 'do_action' ) ) {
@do_action( 'litespeed_purge_url', $url );
}
// W3 Total Cache
if ( function_exists( 'w3tc_flush_url' ) ) {
@w3tc_flush_url( $url );
} elseif ( function_exists( 'w3tc_flush_all' ) ) {
@w3tc_flush_all();
}
// WP Super Cache
if ( function_exists( 'wp_cache_clear_cache' ) ) {
@wp_cache_clear_cache( get_current_blog_id() );
}
// Hızlı Object Cache temizliği
if ( function_exists( 'wp_cache_flush' ) ) {
@wp_cache_flush();
}
}
/**
* Yoast taxonomy meta'yı güvenli şekilde set eder ve görünümü zorla yeniler.
*/
function ycu_set_yoast_term_meta( $term_id, $taxonomy, $title_tpl, $desc_or_null ) {
$opt_name = 'wpseo_taxonomy_meta';
$store = get_option( $opt_name );
if ( ! is_array( $store ) ) {
$store = [];
}
if ( ! isset( $store[ $taxonomy ] ) || ! is_array( $store[ $taxonomy ] ) ) {
$store[ $taxonomy ] = [];
}
if ( ! isset( $store[ $taxonomy ][ $term_id ] ) || ! is_array( $store[ $taxonomy ][ $term_id ] ) ) {
$store[ $taxonomy ][ $term_id ] = [];
}
// Başlık şablonu.
$store[ $taxonomy ][ $term_id ]['wpseo_title'] = $title_tpl;
// Açıklama varsa kopyala; boşsa mevcutu koru.
if ( is_string( $desc_or_null ) && $desc_or_null !== '' ) {
$store[ $taxonomy ][ $term_id ]['wpseo_desc'] = $desc_or_null;
}
// Seçenek değerini güncelle.
update_option( $opt_name, $store, false );
// 1) Yoast indexable'ı yeniden inşa et.
ycu_rebuild_yoast_indexable_for_term( (int) $term_id, $taxonomy );
// 2) WP edit zincirini tetikle (paneldeki "Güncelle"yi taklit).
ycu_trigger_wp_edit_hooks( (int) $term_id, $taxonomy );
// 3) İlgili arşiv URL'si için cache temizliği yap.
$link = get_term_link( (int) $term_id, $taxonomy );
if ( ! is_wp_error( $link ) ) {
ycu_purge_caches_for_url( $link );
}
}
/**
* Yönetim sayfası.
*/
function ycu_admin_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
}
// Form gönderimi.
if ( isset( $_POST['ycu_update'] ) ) {
check_admin_referer( 'ycu_update_categories', 'ycu_nonce' );
$selected_ids = isset( $_POST['categories'] ) ? array_map( 'intval', (array) $_POST['categories'] ) : [];
$updated = [];
foreach ( $selected_ids as $cat_id ) {
$term = get_term( $cat_id, 'category' );
if ( $term && ! is_wp_error( $term ) ) {
$description_html = term_description( $cat_id, 'category' );
$clean_desc = wp_strip_all_tags( (string) $description_html );
$title_tpl = '%%term_title%% %%page%% %%sep%% %%sitename%%';
ycu_set_yoast_term_meta(
$cat_id,
'category',
$title_tpl,
( $clean_desc !== '' ? $clean_desc : null )
);
$updated[] = $term->name;
}
}
if ( ! empty( $updated ) ) {
printf(
'<div class="updated notice is-dismissible"><p>%s</p></div>',
esc_html( 'Güncellenen kategoriler: ' . implode( ', ', $updated ) )
);
} else {
echo '<div class="notice notice-warning is-dismissible"><p>Güncellenecek geçerli kategori bulunamadı.</p></div>';
}
}
$categories = get_terms( [
'taxonomy' => 'category',
'hide_empty' => false,
'fields' => 'all',
] );
?>
<div class="wrap">
<h1>Yoast Kategori Güncelleme</h1>
<form method="post">
<?php wp_nonce_field( 'ycu_update_categories', 'ycu_nonce' ); ?>
<p>
<label>
<input type="checkbox" id="ycu-select-all"> <strong>Tümünü Seç</strong>
</label>
</p>
<div style="max-height:420px;overflow:auto;border:1px solid #ccd0d4;padding:8px;background:#fff;">
<?php
if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) :
foreach ( $categories as $cat ) : ?>
<p style="margin:4px 0;">
<label>
<input type="checkbox" name="categories[]" value="<?php echo esc_attr( $cat->term_id ); ?>">
<?php echo esc_html( $cat->name ); ?>
<small style="color:#666;">(ID: <?php echo (int) $cat->term_id; ?>)</small>
</label>
</p>
<?php endforeach;
else :
echo '<p>Kategori bulunamadı.</p>';
endif;
?>
</div>
<p><input type="submit" name="ycu_update" class="button button-primary" value="Seçilenleri Güncelle"></p>
</form>
<script>
(function(){
const all = document.getElementById('ycu-select-all');
if (!all) return;
all.addEventListener('click', function() {
const checkboxes = document.querySelectorAll('input[name="categories[]"]');
for (const cb of checkboxes) { cb.checked = this.checked; }
});
})();
</script>
</div>
<?php
}
/* İsteğe bağlı: Tema başlığındaki "Category Archives:" kalıbını sadeleştirmek için aşağıyı açın.
add_filter( 'get_the_archive_title', function( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false ); // sadece kategori adı
}
return $title;
} );
*/