用途
ストア全体・商品詳細ページ・ブログ記事ページで Google 検索結果の拡張表示(商品スニペット、記事スニペット、サイトリンク検索)を狙うとき。マルチタイプ構造化データを一箇所で管理したいときに活用する。
設置場所
snippets/rich-snippets.liquid に配置し、theme.liquid の </head> 直前で `{% render 'rich-snippets' %}` で呼び出す。または、各テンプレート(product.liquid、article.liquid)内で条件分岐で呼び出してもよい。
注意点
テーマ設定でロゴ URL とソーシャルメディアリンク(Facebook、Instagram、X、TikTok など)が入力されていることが前提。Product 型の price は `divided_by: 100.00` で小数点に変換しているため、Shopify の内部価格表現(セント単位)を理解しておく。GS1 バーコード(gtin12・gtin13・gtin14)はバリアントの barcode フィールドの桁数で自動判定しているが、不正なバーコードが混在するとバリデーションエラーになるため事前にデータ検証を行う。Google Search Console の URL 検査ツールで各ページの構造化データエラーを確認し、欠落フィールド(brand、availability など)がないか定期的にチェックする。
コード
126 行 / liquid<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": {{ shop.name | json }},
{% if settings.logo != nil %}
"logo": {{ settings.logo | image_url: width: 500 | prepend: "https:" | json }},
{% endif %}
"sameAs": [
{{ settings.social_facebook | json }},
{{ settings.social_instagram | json }},
{{ settings.social_x | json }},
{{ settings.social_tiktok | json }},
{{ settings.social_pinterest | json }},
{{ settings.social_snapchat | json }},
{{ settings.social_youtube | json }},
{{ settings.social_linkedin | json }}
],
"url": {{ request.origin | append: page.url | json }}
}
</script>
{%- if request.page_type == 'index' -%}
{% assign potential_action_target = request.origin | append: routes.search_url | append: "?q={search_term_string}" %}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": {{ shop.name | json }},
"potentialAction": {
"@type": "SearchAction",
"target": {{ potential_action_target | json }},
"query-input": "required name=search_term_string"
},
"url": {{ request.origin | append: page.url | json }}
}
</script>
{%- endif -%}
{%- if request.page_type == 'product' -%}
{%- liquid
if product.selected_or_first_available_variant.featured_media
assign seo_media = product.selected_or_first_available_variant.featured_media
else
assign seo_media = product.featured_media
endif
-%}
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": {{ product.title | json }},
"url": {{ request.origin | append: product.url | json }},
{% if seo_media -%}
"image": [
{{ seo_media | image_url: width: 1920 | prepend: "https:" | json }}
],
{%- endif %}
"description": {{ product.description | strip_html | json }},
{% if product.selected_or_first_available_variant.sku != blank -%}
"sku": {{ product.selected_or_first_available_variant.sku | json }},
{%- endif %}
"brand": {
"@type": "Brand",
"name": {{ product.vendor | json }}
},
"offers": [
{%- for variant in product.variants -%}
{
"@type" : "Offer",
{%- if variant.sku != blank -%}
"sku": {{ variant.sku | json }},
{%- endif -%}
{%- if variant.barcode.size == 12 -%}
"gtin12": {{ variant.barcode }},
{%- endif -%}
{%- if variant.barcode.size == 13 -%}
"gtin13": {{ variant.barcode }},
{%- endif -%}
{%- if variant.barcode.size == 14 -%}
"gtin14": {{ variant.barcode }},
{%- endif -%}
"availability" : "http://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}",
"price" : {{ variant.price | divided_by: 100.00 | json }},
"priceCurrency" : {{ cart.currency.iso_code | json }},
"url" : {{ request.origin | append: variant.url | json }}
}{% unless forloop.last %},{% endunless %}
{%- endfor -%}
]
}
</script>
{%- endif -%}
{%- if request.page_type == 'article' -%}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"articleBody": {{ article.content | strip_html | json }},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{ request.origin | append: page.url | json }}
},
"headline": {{ article.title | json }},
{% if article.excerpt != blank %}
"description": {{ article.excerpt | strip_html | json }},
{% endif %}
{% if article.image %}
"image": [
{{ article | image_url: width: 1920 | prepend: "https:" | json }}
],
{% endif %}
"datePublished": {{ article.published_at | date: '%Y-%m-%dT%H:%M:%SZ' | json }},
"dateCreated": {{ article.created_at | date: '%Y-%m-%dT%H:%M:%SZ' | json }},
"author": {
"@type": "Person",
"name": {{ article.author | json }}
},
"publisher": {
"@type": "Organization",
"name": {{ shop.name | json }}
}
}
</script>
{%- endif -%}