JSON-LDフォーマットのパンくずナビゲーション
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem",
"position": 1,
"item":
{
"@id": "https://example.com/dresses",
"name": "Dresses"
}
},
{
"@type": "ListItem",
"position": 2,
"item":
{
"@id": "https://example.com/dresses/real",
"name": "Real Dresses"
}
}
]
}
</script>
Breadcrumb NavXT で対応
プラグインと対応バージョン
https://ja.wordpress.org/plugins/breadcrumb-navxt/
パンくず系では定番。
デフォルトではRDFaフォーフォーマットで出力します。
JSON-LDフォーマットで出力する関数は bcn_display_json_ld()
でプラグインのバージョン5.7.0以上で対応してます。
出力の仕方
プラグイン作者によるドキュメント
https://mtekk.us/archives/guides/fun-with-bcn_display_json_ld-the-basics/
<head>
タグ内で出力する場合。
<?php
add_action( 'wp_head', 'my_json_ld_breadcrumb_trail', 10 );
function my_json_ld_breadcrumb_trail() {
if ( function_exists( 'bcn_display_json_ld' ) ) {
printf( '<script type="application/ld+json">%s</script>', bcn_display_json_ld( true ) );
}
}
?>
これとは別に見た目でもパンくずを出す場合は今までどり。
テーマのファイルを編集する必要があります。公式ディレクトリ掲載のテーマなら子テーマにしてから作業しましょう。
<?php
if ( function_exists( 'bcn_display' ) ) {
bcn_display();
}
現場からは以上です。