2026年8月29日
2026年8月29日
WordPressにJSON-LD構造化データを追加する方法・リッチリザルト対応
はじめに
「Google検索に星評価や価格が表示されるようにしたい」「FAQ形式のリッチリザルトを出したい」——JSON-LD形式の構造化データをWordPressに追加することで、Googleの検索結果に豊富な情報(リッチリザルト)を表示できます。
症状・原因
構造化データが未実装の場合、検索結果には通常のスニペット(タイトル・URL・説明文)のみ表示されます。Schema.orgに準拠したJSON-LDをページに追加することで、記事の投稿日・著者情報・FAQパネル・商品価格などを検索結果に表示できるようになります。
解決手順
ステップ1:現在の構造化データを確認する
# 構造化データが出力されているか確認
curl -s https://example.com/sample-post/ \
| grep -A 20 'application/ld+json'
# Googleのリッチリザルトテストで検証
# https://search.google.com/test/rich-results
ステップ2:Article(記事)スキーマを追加する
// 投稿ページにArticleスキーマを追加(functions.php)
add_action( 'wp_head', function() {
if ( ! is_singular( 'post' ) ) return;
global $post;
$schema = [
'@context' => 'https://schema.org',
'@type' => 'Article',
'headline' => get_the_title(),
'description' => get_the_excerpt(),
'datePublished' => get_the_date( 'c' ),
'dateModified' => get_the_modified_date( 'c' ),
'author' => [
'@type' => 'Person',
'name' => get_the_author(),
'url' => get_author_posts_url( get_the_author_meta( 'ID' ) ),
],
'publisher' => [
'@type' => 'Organization',
'name' => get_bloginfo( 'name' ),
'logo' => [
'@type' => 'ImageObject',
'url' => get_site_icon_url( 512 ),
],
],
'mainEntityOfPage' => get_permalink(),
];
if ( has_post_thumbnail() ) {
$schema['image'] = get_the_post_thumbnail_url( null, 'large' );
}
echo '<script type="application/ld+json">'
. wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES )
. '</script>' . "\n";
} );
ステップ3:FAQスキーマを追加する
// ショートコード [faq] でFAQスキーマを出力
add_shortcode( 'faq', function( $atts, $content ) {
// FAQデータをカスタムフィールドから取得(例)
$faqs = get_post_meta( get_the_ID(), 'faq_items', true );
if ( ! $faqs ) return '';
$main_entity = [];
foreach ( $faqs as $faq ) {
$main_entity[] = [
'@type' => 'Question',
'name' => $faq['question'],
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => $faq['answer'],
],
];
}
$schema = [
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => $main_entity,
];
return '<script type="application/ld+json">'
. wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES )
. '</script>';
} );
ステップ4:パンくずリストスキーマを追加する
// BreadcrumbListスキーマを出力
add_action( 'wp_head', function() {
if ( ! is_singular() ) return;
$items = [];
$items[] = [
'@type' => 'ListItem',
'position' => 1,
'name' => 'ホーム',
'item' => home_url( '/' ),
];
$categories = get_the_category();
if ( $categories ) {
$items[] = [
'@type' => 'ListItem',
'position' => 2,
'name' => $categories[0]->name,
'item' => get_category_link( $categories[0]->term_id ),
];
$items[] = [
'@type' => 'ListItem',
'position' => 3,
'name' => get_the_title(),
'item' => get_permalink(),
];
}
$schema = [
'@context' => 'https://schema.org',
'@type' => 'BreadcrumbList',
'itemListElement' => $items,
];
echo '<script type="application/ld+json">'
. wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES )
. '</script>' . "\n";
} );
ステップ5:Googleリッチリザルトテストで検証する
# Google Rich Results APIで検証
curl -X POST \
"https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/sample-post/"}'
# ローカルでJSON-LDの構文チェック
php -r "
\$json = file_get_contents('schema.json');
\$data = json_decode(\$json);
echo json_last_error() === JSON_ERROR_NONE ? 'Valid JSON' : 'Error: ' . json_last_error_msg();
"
注意事項
- JSON-LDの内容はページの実際のコンテンツと一致している必要があります。虚偽情報を含む構造化データはGoogleのペナルティ対象になります。
- Yoast SEOやRank Mathは自動的に構造化データを追加します。カスタムコードと重複しないよう注意してください。
wp_json_encode()の第2引数にJSON_UNESCAPED_UNICODEを指定しないと、日本語がUnicodeエスケープされます。
まとめ
JSON-LD構造化データは「現状確認→Articleスキーマ→FAQスキーマ→パンくずスキーマ→検証」の流れで実装できます。Search Consoleの「リッチリザルト」レポートで定期的にエラーを確認し、リッチリザルト表示率を高めましょう。関連記事:WordPressのサイトマップを設定する方法、WordPressでOGPを設定する方法。