Rich Snippets kullanımı (NewsArticle için) için WordPress temalarında bazı değişiklikler yapmamız gerekir. İlk olarak her yazının bulunduğu div’e aşağıdaki şekilde ekleme yapmamız gerekir.
<div class="post" id="post-<?php the_ID(); ?>" itemscope itemtype="http://schema.org/NewsArticle">
Tarih kısmı için aşağıdaki şekilde değiştirebiliriz:
<div class="tarih" itemprop="datePublished" content="<?php the_time('Y-m-d H:i'); ?>">
Başlık kısmı için aşağıdaki ekleme yapılmalı:
<h2 itemprop="headline">
İçerik kısmına da aşağıdakini ekleyebiliriz p ya da div olabilir fark etmez.
<p itemprop="articleBody">
Post thumbnail kullanımını aşağıdaki şekilde yapmamız gerekir:
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thumbnail', array( 'itemprop' => 'image' ) );}; ?>
Son olarak resimler için function.php dosyasına aşağıdaki kodu eklersek tüm resimlere eklemeyi otomatik yapacaktır.
// shema.org icin resimlere ekleme function add_responsive_class($content){ $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); $document = new DOMDocument(); libxml_use_internal_errors(true); $document->loadHTML(utf8_decode($content)); $imgs = $document->getElementsByTagName('img'); foreach ($imgs as $img) { $img->setAttribute('itemprop','image'); } $html = $document->saveHTML(); return $html; } add_filter ('the_content', 'add_responsive_class');