METAタグにthumbnailを追加

ホームページ制作

Google検索で画像表示が追加されやすくするために、METAタグにサムネイルを追加した。

※WordPressのheader.phpに追加

<?php
  if (is_single() && has_post_thumbnail($post_object->ID)) {
    $thumbnail_id = get_post_thumbnail_id($post_object->ID);
    $image = wp_get_attachment_image_src( $thumbnail_id, 'full' );
    $thumbnail_image = $image[0];
  } else {
    $thumbnail_image = get_template_directory_uri().'/images/thumbnail.png';
  }
?>
<meta name="thumbnail" content="<?php echo $thumbnail_image; ?>">
Translate »