Amatör arkadaşlara bir kıyak yapıp şu iki güzel fonksiyonu yazayım. Sayfanıza SEO değeri katacak description ve keywords meta etiketlerini bunlarla herhangi bir eklenti kullanmadan yapabilirsiniz.
Description için excerpt den veri çekiliyor, temanın functions.php dosyasına aşağıdakini eklemeliyiz, bu fonksiyon girdilerden içerik alacak, kategori açıklamalarını alacak ana sayfa ve etiket sayfalarında ise varsayılan açıklamayı ekleyecek.
function meta_description() {
/* >> bu kısımda istediğiniz değişiklikleri yapın */
$default_blog_desc = 'Guncel Turkce blog. - Volkan Yilmaz ve saz arkadaslari web gunlugu.'; // varsayılan description (etiket sayfaları ve ana sayfa)
$post_desc_length = 22; // maksimum description uzunluğu
$post_use_excerpt = 1;
$custom_desc_key = ’description'; // girdilere description isimli bir özel alan eklerseniz onun ismi.
/* << bu kısımda istediğiniz değişiklikleri yapın */
global $cat, $cache_categories, $wp_query, $wp_version;
if(is_single() || is_page()) {
$post = $wp_query->post;
$post_custom = get_post_custom($post->ID);
$custom_desc_value = $post_custom["$custom_desc_key"][0];
if($custom_desc_value) {
$text = $custom_desc_value;
} elseif($post_use_excerpt && !empty($post->post_excerpt)) {
$text = $post->post_excerpt;
} else {
$text = $post->post_content;
}
$text = str_replace(array("rn", "r", "n", " "), " ", $text);
$text = str_replace(array("""), "", $text);
$text = trim(strip_tags($text));
$text = explode(' ', $text);
if(count($text) > $post_desc_length) {
$l = $post_desc_length;
$ellipsis = '';
} else {
$l = count($text);
$ellipsis = '';
}
$description = '';
for ($i=0; $i<$l; $i++)
$description .= $text[$i] . ' ';
$description .= $ellipsis;
} elseif(is_category()) {
$category = $wp_query->get_queried_object();
$description = trim(strip_tags($category->category_description));
} else {
$description = (empty($default_blog_desc))? trim(strip_tags(get_bloginfo(’description'))): $default_blog_desc;
}
if($description) {
echo "$description";
}
}
Yukarıdakini kullanmak için örnek:
<meta name="description" content="<?php echo meta_description(); ?>” />
Aşağıdaki girdideki etiketlerin isimlerini yazdıran fonksiyon, bunu hem temanın fonksiyon dosyasına bir fonksiyon aatyarak hem de manuel kullanabilirsiniz. Temanın functions.php dosyasına eklenecek kod aşağıdaki gibi.
function terimler() {
$posttags = get_the_tags();
if ($posttags) {
foreach ($posttags as $tag) {
$tagnames[count($tagnames)] = $tag->name;
}
$comma_separated_tagnames = implode(", ", $tagnames);
print_r($comma_separated_tagnames);
}
return $terimler;
}
Bunu kulanmak için örnek:
<meta name="keywords" content="<?php echo terimler(); ?>” />
Gördüğünüz gibi çok basit şeyler, bunları farklı şekillerde de kullanabilirsiniz sadece meta etiketleri değil, kolay gelsin.