Googleの検索結果に最終更新日と今更だけど著者情報を表示させる為の再挑戦。

Googleの期間指定での検索結果に

公開日より最終更新日の方が新しければ、最終更新日を反映させたいと思いやってみて数か月。

そろそろ、反映されてるかと思ったけども・・・

Google 検索結果

なにがいけないんだろうと改めて検索してみると、出てこなかったのか目に入らなかったのか、当時は意識外の情報が。

改めて、構造化データ テスト ツールで確認してみると

エラー: Missing required field “entry-title”.
エラー: Missing required field “updated”.
エラー: Missing required hCard “author”.

のエラーが・・・

 

日付に関しては「エラー: Missing required field “updated”.」が関係ありそう。

著者情報に関しては「エラー: Missing required hCard “author”.」。

 

このエラーを無くせば良いのでは?ということで、前回の対処に付け加えたことを記し、また数週間後に確認してみたいと思います。

 

前回の対処はこちら↓

 

エラー回避

まずは、エラーを無くすために付け加えたこと。

エラー: Missing required field “entry-title”.への対処

single.php(個別記事テンプレート)で、タイトル部分を探して”class entry-title”を付け加える。

<h2 class="title"><?php the_title(); ?></h2>

<h2 class="title entry-title"><?php the_title(); ?></h2>

に。

 

エラー: Missing required field “updated”.への対処

日付部分

single.php(個別記事テンプレート)で日付表示部分を探して ”class  date updated”を付け加える。

ねこもりやの場合、この部分長いのでmeta.phpという別ファイルにしてテンプレートに読み込んでいます。

詳しくは、前回の投稿をご参考に→Googleの検索結果の日付を最終更新日にする為にやってみたこと。

<?php if (get_the_modified_date('Y/n/j') != get_the_time('Y/n/j')) : ?>
<span class="new">
<?php
$days=3; //UPをつける日数
$today=date_i18n('U');
$entry=get_the_modified_date('U');
$sa=date('U',($today - $entry))/86400;
if( $days > $sa ){
echo '<img src="';
bloginfo('template_directory');
echo '/img/up.png" width="30" height="15" alt="up" />';

}
?>
<time class="entry-date" datetime="<?php the_modified_time('c') ?>"><?php if ($mtime = get_mtime('Y年m月d日 l')) echo '最終更新日: ', $mtime; ?></time>
</span> 
<?php endif; ?>
<br /> 
<span class="new">
<?php
$days = 3; //Newを表示させたい期間の日数
$today = date_i18n('U');
$entry = get_the_time('U');
$kiji = date('U',($today - $entry)) / 86400 ;
if( $days > $kiji ){
echo '<img src="';
bloginfo('template_directory');
echo '/img/new.png" width="30" height="15" alt="new" />';

}
?>
<?php if (get_the_modified_date('Y/n/j') == get_the_time('Y/n/j')) : ?>
公開日:<time class="entry-date" datetime="<?php the_time('c') ;?>"><?php the_time('Y年m月d日 l') ?></time>
<?php elseif (get_the_modified_date('Y/n/j') != get_the_time('Y/n/j')) : ?>
公開日:<?php the_time('Y年m月d日 l') ?>
<?php endif; ?>
</span>

<p class="meta">
<?php if (get_the_modified_date('Y/n/j') != get_the_time('Y/n/j')) : ?>
<span class="new">
<?php
$days=3; //UPをつける日数
$today=date_i18n('U');
$entry=get_the_modified_date('U');
$sa=date('U',($today - $entry))/86400;
if( $days > $sa ){
echo '<img src="';
bloginfo('template_directory');
echo '/img/up.png" width="30" height="15" alt="up" />';

}
?>
<time class="entry-date date updated" datetime="<?php the_modified_time('c') ?>"><?php if ($mtime = get_mtime('Y年m月d日 l')) echo '最終更新日: ', $mtime; ?></time>
</span> 
<?php endif; ?>
<br /> 
<span class="new">
<?php
$days = 3; //Newを表示させたい期間の日数
$today = date_i18n('U');
$entry = get_the_time('U');
$kiji = date('U',($today - $entry)) / 86400 ;
if( $days > $kiji ){
echo '<img src="';
bloginfo('template_directory');
echo '/img/new.png" width="30" height="15" alt="new" />';

}
?>
<?php if (get_the_modified_date('Y/n/j') == get_the_time('Y/n/j')) : ?>
公開日:<time class="entry-date date published updated" datetime="<?php the_time('c') ;?>"><?php the_time('Y年m月d日 l') ?></time>
<?php elseif (get_the_modified_date('Y/n/j') != get_the_time('Y/n/j')) : ?>
公開日:<span class="date published"><?php the_time('Y年m月d日 l') ?></span>
<?php endif; ?>
</span> 
<span><a href="<?php bloginfo('home'); ?>/?monthnum=<?php the_time('m') ?>&amp;day=<?php the_time('d') ?>" class="olddays">〇年前のこの日、何してた?</a></span>				
<br /> 
				<?php if ( count( get_the_category() ) ) : ?>
					<?php printf( __( 'Categories: %2$s', 'ari' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
					|
				<?php endif; ?>
				<?php
					$tags_list = get_the_tag_list( '', ', ' );
					if ( $tags_list ):
				?>
					<?php printf( __( 'Tags: %2$s', 'ari' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
					|
				<?php endif; ?>
				閲覧数:<?php if ( function_exists ( 'wpp_get_views' ) ) { echo wpp_get_views ( get_the_ID() ); } ?>
					|				
				<?php comments_popup_link( __( 'Leave a comment', 'ari' ), __( '1 comment', 'ari' ), __( '% comments', 'ari' ) ); ?>
				<?php edit_post_link( __( 'Edit', 'ari' ), '| ', '' ); ?></p>

に。

 

投稿や更新から三日間はNew!アイコンなんかをつけるようにしてるのに加えて、条件分岐で色々やってるので長いです。

解説すると、更新日が公開日より新しい場合は、更新日に日付データとして認識するように、

<time class="entry-date

”timeタグ”をつけています。

もし、更新日が公開日より古い場合は、公開日に同様に

<time class="entry-date

としています。

なので、

更新日を日付データにする場合、

<time class="entry-date date updated" datetime="<?php the_modified_time('c') ?>"><?php if ($mtime = get_mtime('Y年m月d日 l')) echo '最終更新日: ', $mtime; ?></time>

公開日の日付はtimeタグではなく、spanタグで

公開日:<span class="date published"><?php the_time('Y年m月d日 l') ?></span>

としました。

 

公開日が日付データになる場合の部分は、

公開日:<time class="entry-date date published updated" datetime="<?php the_time('c') ;?>"><?php the_time('Y年m月d日 l') ?></time>

です。

 

これで、良いのかどうかはわかりませんが、とりあえずエラーはなくなったので良しとして。

Google Structured Data Testing Tool

 

エラー: Missing required hCard “author”.

最後に「エラー: Missing required hCard “author”. 」への対処。

これをちゃんと設定できれば、検索結果に著者情報として載るのかな?

footer.php(フッターテンプレート)に以下を追加。

by<span class="vcard author"><span class="fn n"><a href="https://plus.google.com/u/0/Google+の自分のプロフィールページ/posts" rel="author"><span class="family-name">苗字</span><span class="given-name">名前</span></a></span>

加えて、single.phpに著者情報を表示しているなら、

著者<span class="vcard author"><span class="fn nickname"><?php get_the_author() ; ?></span></span>

とする。

ねこもりやの場合、ニックネームを表示しているので ”fn nickname”にしてますが本名の場合”fn”だけで良いかなと。

著者情報

参考サイト

「entry-title がありません」「updated がありません」「author がありません」ウェブマスターツール 構造化データ(hentry)のエラーへの対応策 | 田舎に住みたいエンジニアの日記

検索結果内の著者情報 – ウェブマスター ツール ヘルプ

後記

まだ、施したばかりでどうなるかはわからないのだけど

数週間後には結果が出るでしょう。

またこちらでご報告できればと思います。

 

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA