Розмітка статті wordpress schema.org

Блог Фрилансера 3 хвилин 35 секунд 14 лют. 2019
 Розмітка статті wordpress schema.org

Файл single.php

До блоку зі статті додаємо 

itemscope itemtype="http://schema.org/Article"

заміна зображення в тексті з розміткою

function mayak_filter_image($content) {
$ar_mk = '!<img (.*?) width="(.*?)" height="(.*?)" (.*?)/>!si';
$br_mk = '<span itemprop="image" itemscope itemtype="https://schema.org/ImageObject"><img itemprop="url contentUrl" \\1 width="\\2" height=" \\3" \\4/><meta itemprop="width" content="\\2"><meta itemprop="height" content="\\3"></span>' ;
if(preg_match($ar_mk, $content)){

$content = preg_replace($ar_mk, $br_mk, $content);

}else{
$content = $content.'<span itemprop="image" itemscope="" itemtype="https://schema.org/ImageObject"><img itemprop="url contentUrl" class="alignnone size-full wp-image-1617" src="https://brusovoy.ru/wp-content/themes/brusovoy/assets/img/logo_head.png" alt="" width="1200" height="900" srcset=" https://brusovoy.ru/wp-content/themes/brusovoy/assets/img/logo_head.png 250w, https://brusovoy.ru/wp-content/themes/brusovoy/assets/img/logo_head.png 250w" sizes="(max-width: 250px) 100vw, 250px"><meta itemprop="width" content="250"><meta itemprop="height" content="900"></st ;';
  
}
  return $content;
}
add_filter('the_content', 'mayak_filter_image');

Заголовок 

 <h2 class="main_title" itemid="<?php the_permalink() ?>" itemprop="mainEntityOfPage">
            <span itemprop="headline" class="articles_arch__title"><?php the_title(); ?></span>
 </h2>

Тіло статті обертаємо 

<div itemprop="articleBody" class="articles_arch__item__text">
          <?php the_content(); ?>
</div>

Додаємо автора. Дату додавання та дату зміни Додаємо у функцію

 <span itemprop="author"><?php the_author_posts_link(); ?></span>
              <meta itemprop="datePublished" content="<?php the_time('Y-m-d') ?>" /><?php the_time('d.m.Y') ?>
              <meta itemprop="dateModified" content="<?php the_modified_time('Y-m-d')?>" />
              <div itemprop="publisher" itemscope itemtype="https://schema.org/Organization">
                  <div itemprop="logo image" itemscope itemtype="https://schema.org/ImageObject">
                      <img itemprop="url contentUrl" src="<?php echo esc_url(get_template_directory_uri()); ?>/images/logo.jpg" alt="logo" />
                      <meta itemprop="width" content="6" />
                      <meta itemprop="height" content="6" />
                 </div>
                 <meta itemprop="name" content="<?php bloginfo('name'); ?>" />
                 <meta itemprop="address" content="" />
                 <meta itemprop="telephone" content="" />
              </div>

Щоб перевірити, чи працює ваша розмітка. Перевіряємо сервісом Google