SEO ve Yapay Zeka
WordPress sitemin SEO performansını artırmak için Ai ile functions.php ne eklenebilir?
Aşağıda, WordPress sitenizin SEO performansını artırmak için functions.php dosyanıza ekleyebileceğiniz faydalı kodları bulabilirsiniz:
<?php
// ======================
// WordPress SEO OPTIMIZASYON KODLARI
// functions.php dosyasına eklenmelidir
// ======================
// 1. OTMATIK TITLE TAG DESTEĞİ
function theme_slug_setup() {
add_theme_support('title-tag');
}
add_action('after_setup_theme', 'theme_slug_setup');
// 2. META AÇIKLAMALAR İÇİN EXCERPT KULLANIMI
function excerpt_for_meta_description() {
add_post_type_support('page', 'excerpt');
}
add_action('init', 'excerpt_for_meta_description');
// 3. OTMATIK META AÇIKLAMA OLUŞTURMA
function auto_meta_description() {
global $post;
if (is_singular()) {
$description = strip_tags($post->post_excerpt);
$description = strip_shortcodes($description);
if (empty($description)) {
$description = strip_tags($post->post_content);
$description = strip_shortcodes($description);
$description = str_replace(array("\n", "\r", "\t"), ' ', $description);
$description = substr($description, 0, 155);
}
echo '<meta name="description" content="' . esc_attr($description) . '" />' . "\n";
}
}
add_action('wp_head', 'auto_meta_description');
// 4. CANONICAL URL'LERİ AKTİF ETME
function canonical_for_single_posts() {
if (is_singular()) {
echo '<link rel="canonical" href="' . get_permalink() . '" />' . "\n";
}
}
add_action('wp_head', 'canonical_for_single_posts');
// 5. WORDPRESS SÜRÜM NUMARASINI KALDIRMA
remove_action('wp_head', 'wp_generator');
// 6. JSON-LD İŞARETLEME İLE SCHEMA.ORG DESTEĞİ
function json_ld_schema() {
if (is_singular('post')) {
global $post;
$author = get_the_author_meta('display_name', $post->post_author);
$site_url = get_site_url();
$logo = get_theme_mod('custom_logo');
$image = wp_get_attachment_image_src($logo, 'full');
$site_name = get_bloginfo('name');
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Article',
'mainEntityOfPage' => array(
'@type' => 'WebPage',
'@id' => get_permalink(),
),
'headline' => get_the_title(),
'description' => wp_strip_all_tags(get_the_excerpt(), true),
'image' => array(
'@type' => 'ImageObject',
'url' => get_the_post_thumbnail_url($post->ID, 'full'),
),
'author' => array(
'@type' => 'Person',
'name' => $author,
),
'publisher' => array(
'@type' => 'Organization',
'name' => $site_name,
'logo' => array(
'@type' => 'ImageObject',
'url' => $image[0],
),
),
'datePublished' => get_the_date('c'),
'dateModified' => get_the_modified_date('c'),
);
echo '<script type="application/ld+json">' . json_encode($schema) . '</script>';
}
}
add_action('wp_head', 'json_ld_schema', 5);
// 7. RESİMLER İÇİN LAZY LOADING EKLEME
function add_lazy_loading_to_images($content) {
if (is_feed() || is_preview() || wp_is_json_request()) {
return $content;
}
$content = preg_replace_callback('/<img[^>]+/', function($matches) {
$img = $matches[0];
if (strpos($img, 'loading=') === false) {
$img = preg_replace('/<img(.*?)(\/?)>/i', '<img$1 loading="lazy"$2>', $img);
}
return $img;
}, $content);
return $content;
}
add_filter('the_content', 'add_lazy_loading_to_images', 10);
// 8. OTMATIK ALT ETİKET OLUŞTURMA
function auto_image_alt($content) {
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if (!is_null($images)) {
foreach ($images[1] as $index => $value) {
if (!preg_match('/alt=/', $value)) {
$new_img = str_replace('<img', '<img alt="' . esc_attr(get_the_title()) . '"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'auto_image_alt', 9999);
// 9. AÇIKLAMA KISALTMA
function excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'excerpt_length', 999);
// 10. DAHA FAZLA OKU BAĞLANTISI
function excerpt_more($more) {
return '... <a class="read-more" href="' . get_permalink(get_the_ID()) . '">' . __('Devamını Oku', 'textdomain') . '</a>';
}
add_filter('excerpt_more', 'excerpt_more');
// 11. XML SITEMAP DESTEĞİ
function xml_sitemap() {
$postsForSitemap = get_posts(array(
'numberposts' => -1,
'orderby' => 'modified',
'post_type' => array('post', 'page'),
'order' => 'DESC'
));
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach ($postsForSitemap as $post) {
setup_postdata($post);
$postdate = explode(" ", $post->post_modified);
$sitemap .= '<url>'.
'<loc>' . get_permalink($post->ID) . '</loc>' .
'<lastmod>' . $postdate[0] . '</lastmod>' .
'<changefreq>monthly</changefreq>' .
'</url>';
}
$sitemap .= '</urlset>';
$fp = fopen(ABSPATH . 'sitemap.xml', 'w');
fwrite($fp, $sitemap);
fclose($fp);
}
add_action('publish_post', 'xml_sitemap');
add_action('publish_page', 'xml_sitemap');
// 12. BREADCRUMB (İÇERİK YOLU) DESTEĞİ
function custom_breadcrumbs() {
if (!is_home()) {
echo '<nav class="breadcrumb">';
echo '<a href="' . home_url() . '">Ana Sayfa</a> » ';
if (is_category() || is_single()) {
the_category(' » ');
if (is_single()) {
echo " » ";
the_title();
}
} elseif (is_page()) {
echo the_title();
}
echo '</nav>';
}
}
// 13. PAGINATION (SAYFALAMA) OPTIMIZASYONU
function custom_pagination() {
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'prev_text' => __('« Önceki'),
'next_text' => __('Sonraki »'),
));
}
// 14. GEREKSİZ STİL VE SCRIPTLERİ KALDIRMA
function remove_unnecessary_assets() {
// Emoji'leri kaldır
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
// Embed scriptlerini kaldır
wp_deregister_script('wp-embed');
// REST API linklerini kaldır
remove_action('wp_head', 'rest_output_link_wp_head', 10);
}
add_action('init', 'remove_unnecessary_assets');
// 15. OPEN GRAPH META ETİKETLERİ
function add_open_graph_tags() {
if (is_singular()) {
global $post;
echo '<meta property="og:title" content="' . get_the_title() . '" />';
echo '<meta property="og:description" content="' . wp_strip_all_tags(get_the_excerpt(), true) . '" />';
echo '<meta property="og:url" content="' . get_permalink() . '" />';
echo '<meta property="og:type" content="article" />';
echo '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />';
if (has_post_thumbnail($post->ID)) {
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
echo '<meta property="og:image" content="' . esc_url($thumbnail_src[0]) . '" />';
}
}
}
add_action('wp_head', 'add_open_graph_tags');
// 16. TWITTER CARD DESTEĞİ
function add_twitter_cards() {
if (is_singular()) {
global $post;
echo '<meta name="twitter:card" content="summary_large_image">';
echo '<meta name="twitter:title" content="' . get_the_title() . '">';
echo '<meta name="twitter:description" content="' . wp_strip_all_tags(get_the_excerpt(), true) . '">';
if (has_post_thumbnail($post->ID)) {
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
echo '<meta name="twitter:image" content="' . esc_url($thumbnail_src[0]) . '">';
}
}
}
add_action('wp_head', 'add_twitter_cards');
?>
Önemli Uyarılar:
- Yedek Alın: functions.php dosyasında değişiklik yapmadan önce mutlaka yedek alın.
- Child Theme Kullanın: Tema güncellemelerinde kodlarınızın silinmemesi için child theme kullanın.
- Test Ortamı: Önce test ortamında deneyin, sonra canlı siteye uygulayın.
- Eklenti Çakışmaları: Bu kodlarla aynı işlevi gören eklentileri kullanmayın (örneğin, Yoast SEO ile çakışabilir).
Bu kodlar, WordPress sitenizin SEO performansını önemli ölçüde artıracak ve arama motorlarında daha iyi sıralamalar almanıza yardımcı olacaktır.