【LION BLOGカスタマイズ】data-vocabulary.org schema deprecated の警告を解消する

【LION BLOGカスタマイズ】data-vocabulary.org schema deprecated の警告を解消する

こんばんは。とらです。

先日Googleさんからこんなメールが…。(1/22 4:45)

タイトル:「パンくずリスト」の問題が新たに 検出されました

所有者様

Search Console により、貴サイトに影響する「パンくずリスト」関連の問題が 1 件検出されました。

主な警告

警告は、サイトの改善のための推奨項目です。警告によっては、検索結果での表示に影響がある場合がございます。また、警告が今後エラーになることも考えられます。貴サイトでは、以下の警告が検出されました。

上記の問題をできる限り解決されることをおすすめいたします。こうした問題を解消することで、サイトのエクスペリエンスや Google 検索結果での表示を最適化できます。

寝起きの警告は状況を先送りにする効果が非常に高いことがわかりました。(朝早すぎて、そっ閉じしたよ)

何が悪いって、メールのリンクを踏んでも何が起きてるかわからないんですよね。

パンくずリストが問題なのはわかりますけど。

ということで、1週間ほどたっぷり寝かして対応しました。

注意:先ほど対応したばっかりでホントにサーチコンソール上で解決できたかまだ確認できてません。(言い訳)

Advertisement

data-vocabulary.org schema deprecated とはなにか

そのまま訳すと「data-vocabulary.orgの形式は非推奨ですよ。」です。(意味不明)

data-vocabulary.org

「data-vocabulary.org」とは、構造化データの規格の1つです。

この規格は古いものなので、Googleはこのサポートを2020年4月6日に終了する予定です。

※2020年1月21日に発表(Sunsetting support for data-vocabulary

構造化データ

構造化データとは、Webサイトの内容をより正しく・明確に検索エンジンに伝えるための記述方法です。

例を出すと、Webサイトで会社名を書こうとする場合はdivやpやらで「〇〇株式会社」と書きますよね。

<div>〇〇株式会社</div>

ですね。

表示するだけであれば何の問題もないのですが、検索エンジン(Googleさん)からすると「なんか文字列書いてるね」なのです。

つまり、文字列の中身を理解できなければ「この情報が何なのか」を理解できない状態です。

※Googleさんはここに「会社名」が書かれていることが理解できない。

なので、構造化データで記述することで、ここに「会社名を書いている」ことを検索エンジンにも伝えましょうということになり、下記のような感じにします。

<div itemscope itemtype="http://schema.org/Corporation">
<span itemprop="name">〇〇株式会社</span>
</div>

この状態で初めて、人と検索エンジンが同じ理解をすることができます。(めでたし)

Googleは検索結果に影響する「可能性がある」と言っているので、はっきりとはしませんが悪影響は回避できるかと思います。

個人ブログのようなものであればまだ良いですが、企業の何百万ものアクセスを持つサイトだとほっとけないですね。

schema.org

上記の説明の通り、この警告が出ているサイトは「今の構造化データの書き方は近々サポートしなくなるから書き換えてね」という状態になっているということでした。

※最初のメールでこう書いてくれてても良いんじゃないかと思う

では、どうするかというと「data-vocabulary.org」から「schema.org」へ変更します。

schema.orgも構造化データの規格ですが、現在最も普及しているようです。

さきほどのGoogleのブログ(Sunsetting support for data-vocabulary)や、他のブログ(mariweb)でも紹介されているとおりschema.orgを使用すると記述量が増えますが、そこまで難しい作業内容でもないので焦らず丁寧に作業すれば良きです。作業後はリッチリザルトテストやサーチコンソールで確認してね!

Advertisement

問題はブログテーマ(今回はLION BLOG)

さて、何をやれば良いかわかったものの多くの人が困っている問題としては、普段ブログ書いてるけどテーマのカスタマイズ(php)とかよくわからない…。という場合かと思います。

自作のテーマ以外のものをお使いの方は、テーマ作成元がすでに対応を始めているところもあるようなので少し待っていれば良いでしょうが、いち早く何とかしたい方もいると思います。

ちなみに本ブログはfitさんのLION BLOGを使用しています。

※2020/1/28現在、まだ動き無いようでした。まだかなぁ。

そのうち対応してもらえるのかなぁとも思いつつ、勉強も兼ねて修正してみました。

修正内容

編集場所:外観→テーマエディター→LION BLOG を選択→テーマのための関数(function.php)を選択

「function fit_breadcrumb」が該当部分になります。

注意:先ほど対応したばっかりでホントにサーチコンソール上で解決できたかまだ確認できてません。(言い訳)

ソースコードはこちらです。

//////////////////////////////////////////////////
//オリジナルパンくずリストを作成
//////////////////////////////////////////////////
function fit_breadcrumb( $args = array() ){
global $post;
$str ='';
$defaults = array(
'class' => "breadcrumb",
'home' => "HOME",
'search' => "の検索結果 ",
'tag' => "",
'author' => "",
'notfound' => "Hello! My Name Is 404",
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );

if( !is_home() && !is_admin() ){
$str.= '<div class="'. $class .'" >';
$str.= '<div class="container" >';
$str.= '<ol itemscope itemtype="http://schema.org/BreadcrumbList" class="breadcrumb__list">';
$str.= '<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. home_url() .'/" itemprop="item"><span class="icon-home" itemprop="name">'. $home .'</span></a><meta itemprop="position" content="1" /></li>';
$my_taxonomy = get_query_var( 'taxonomy' );
$cpt = get_query_var( 'post_type' );

if( $my_taxonomy && is_tax( $my_taxonomy ) ) {
$my_tax = get_queried_object();
$post_types = get_taxonomy( $my_taxonomy )->object_type;
$cpt = $post_types[0];
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="' .get_post_type_archive_link( $cpt ).'" itemprop="item"><span itemprop="name">'. get_post_type_object( $cpt )->label.'</span></a><meta itemprop="position" content="1" /></li>';

if( $my_tax -> parent != 0 ) {
$ancestors = array_reverse( get_ancestors( $my_tax -> term_id, $my_tax->taxonomy ) );

foreach( $ancestors as $ancestor ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_term_link( $ancestor, $my_tax->taxonomy ) .'" itemprop="item"><span itemprop="name">'. get_term( $ancestor, $my_tax->taxonomy )->name .'</span></a><meta itemprop="position" content="1" /></li>';
}
}
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $my_tax -> name . '</span><meta itemprop="position" content="2" /></li>';
}

elseif( is_category() ) {
$cat = get_queried_object();
if( $cat -> parent != 0 ){
$ancestors = array_reverse( get_ancestors( $cat -> cat_ID, 'category' ));
foreach( $ancestors as $ancestor ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_category_link( $ancestor ) .'" itemprop="item"><span itemprop="name">'. get_cat_name( $ancestor ) .'</span></a><meta itemprop="position" content="1" /></li>';
}
}
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $cat -> name . '</span><meta itemprop="position" content="2" /></li>';
}

elseif( is_post_type_archive() ) {
$cpt = get_query_var( 'post_type' );
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. get_post_type_object( $cpt )->label . '</span><meta itemprop="position" content="1" /></li>';
}

elseif( $cpt && is_singular( $cpt ) ){
$taxes = get_object_taxonomies( $cpt );
$mytax = $taxes[0];
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="' .get_post_type_archive_link( $cpt ).'" itemprop="item"><span itemprop="name">'. get_post_type_object( $cpt )->label.'</span></a><meta itemprop="position" content="1" /></li>';
$taxes = get_the_terms( $post->ID, $mytax );
$tax = get_youngest_tax( $taxes, $mytax );

if( $tax -> parent != 0 ){
$ancestors = array_reverse( get_ancestors( $tax -> term_id, $mytax ) );
foreach( $ancestors as $ancestor ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_term_link( $ancestor, $mytax ).'" itemprop="item"><span itemprop="name">'. get_term( $ancestor, $mytax )->name . '</span></a><meta itemprop="position" content="1" /></li>';
}
}
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_term_link( $tax, $mytax ).'" itemprop="item"><span itemprop="name">'. $tax -> name . '</span></a><meta itemprop="position" content="2" /></li>';
$str.= '<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $post -> post_title .'</span><meta itemprop="position" content="3" /></li>';
}

elseif( is_single() ){
$categories = get_the_category( $post->ID );
$cat = get_youngest_cat( $categories );
if( $cat -> parent != 0 ){
$ancestors = array_reverse( get_ancestors( $cat -> cat_ID, 'category' ) );
foreach( $ancestors as $ancestor ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_category_link( $ancestor ).'" itemprop="item"><span itemprop="name">'. get_cat_name( $ancestor ). '</span></a><meta itemprop="position" content="1" /></li>';
}
}
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_category_link( $cat -> term_id ). '" itemprop="item"><span itemprop="name">'. $cat-> cat_name . '</span></a><meta itemprop="position" content="2" /></li>';
$str.= '<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $post -> post_title .'</span><meta itemprop="position" content="3" /></li>';
}

elseif( is_page() ){
if( $post -> post_parent != 0 ){
$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
foreach( $ancestors as $ancestor ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_permalink( $ancestor ).'" itemprop="item"><span itemprop="name">'. get_the_title( $ancestor ) .'</span></a><meta itemprop="position" content="1" /></li>';
}
}
$str.= '<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $post -> post_title .'</span><meta itemprop="position" content="2" /></li>';
}

elseif( is_date() ){
if( get_query_var( 'day' ) != 0){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_year_link(get_query_var('year')). '" itemprop="item"><span itemprop="name">' . get_query_var( 'year' ). '年</span></a><meta itemprop="position" content="1" /></li>';
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_month_link(get_query_var( 'year' ), get_query_var( 'monthnum' ) ). '" itemprop="item"><span itemprop="name">'. get_query_var( 'monthnum' ) .'月</span></a><meta itemprop="position" content="2" /></li>';
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. get_query_var('day'). '日</span><meta itemprop="position" content="3" /></li>';
}

elseif( get_query_var('monthnum' ) != 0){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a href="'. get_year_link( get_query_var('year') ) .'" itemprop="item"><span itemprop="name">'. get_query_var( 'year' ) .'年</span></a><meta itemprop="position" content="1" /></li>';
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. get_query_var( 'monthnum' ). '月</span><meta itemprop="position" content="2" /></li>';
}

else {
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. get_query_var( 'year' ) .'年</span><meta itemprop="position" content="1" /></li>';
}
}

elseif( is_search() ) {
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">「'. get_search_query() .'」'. $search .'</span><meta itemprop="position" content="1" /></li>';
}

elseif( is_author() ){
$str .='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $author . get_the_author_meta('display_name', get_query_var( 'author' )).'</span><meta itemprop="position" content="1" /></li>';
}

elseif( is_tag() ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $tag . single_tag_title( '' , false ). '</span><meta itemprop="position" content="1" /></li>';
}

elseif( is_attachment() ){
$str.= '<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. $post -> post_title .'</span><meta itemprop="position" content="1" /></li>';
}

elseif( is_404() ){
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'.$notfound.'</span><meta itemprop="position" content="1" /></li>';
}

else{
$str.='<li class="breadcrumb__item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">'. wp_title( '', true ) .'</span><meta itemprop="position" content="1" /></li>';
}

$str.='</ol>';
$str.='</div>';
$str.='</div>';
}
echo $str;
}

 

phpはほぼわからないのですが、作業自体は30分ぐらいで終わりました。

なんとな~くの理解で修正してます。※修正箇所あったら、ごめんなさい。(言い訳)

同じくLION BLOGを利用している方はどうぞ。

Googleは構造化データの書き方(3つある)として、JSON-LDを推奨していますがブログテーマがそうでない場合は今回のようにMicrodataのまま修正する必要があります。

※静的に書いてたら地獄…。

Advertisement

まとめ

久しぶりにブログ関連の記事を書きました。

大事なことはGoogleさんから手紙が届いたら読まずに食べない、もとい、内容をきちんと調べる。ということですね。

今回も勉強になりました。参考までにこちらのブログもどうぞ。

data-vocabulary構造化データによるリッチリザルトのサポートをGoogleが終了、schema.orgへの移行を推奨