Skip to content

Commit

Permalink
Product image seo (Shopify#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoboludo authored Nov 12, 2021
1 parent da13ca3 commit 8e91deb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
20 changes: 14 additions & 6 deletions sections/featured-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,30 @@
<script src="{{ 'product-model.js' | asset_url }}" defer></script>
{%- endif -%}

{%- 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": {{ shop.url | append: product.url | json }},
{%- if product.selected_or_first_available_variant.featured_media -%}
{%- assign media_size = product.selected_or_first_available_variant.featured_media.preview_image.width | append: 'x' -%}
{% if seo_media -%}
{%- assign media_size = seo_media.preview_image.width | append: 'x' -%}
"image": [
{{ product.featured_media | img_url: media_size | prepend: "https:" | json }}
{{ seo_media | img_url: media_size | prepend: "https:" | json }}
],
{%- endif -%}
{%- endif %}
"description": {{ product.description | strip_html | json }},
{%- if product.selected_or_first_available_variant.sku != blank -%}
{% if product.selected_or_first_available_variant.sku != blank -%}
"sku": {{ product.selected_or_first_available_variant.sku | json }},
{%- endif -%}
{%- endif %}
"brand": {
"@type": "Thing",
"name": {{ product.vendor | json }}
Expand Down
20 changes: 14 additions & 6 deletions sections/main-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -477,22 +477,30 @@
<script src="{{ 'product-model.js' | asset_url }}" defer></script>
{%- endif -%}

{%- 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": {{ shop.url | append: product.url | json }},
{%- if product.selected_or_first_available_variant.featured_media -%}
{%- assign media_size = product.selected_or_first_available_variant.featured_media.preview_image.width | append: 'x' -%}
{% if seo_media -%}
{%- assign media_size = seo_media.preview_image.width | append: 'x' -%}
"image": [
{{ product.selected_or_first_available_variant.featured_media | img_url: media_size | prepend: "https:" | json }}
{{ seo_media | img_url: media_size | prepend: "https:" | json }}
],
{%- endif -%}
{%- endif %}
"description": {{ product.description | strip_html | json }},
{%- if product.selected_or_first_available_variant.sku != blank -%}
{% if product.selected_or_first_available_variant.sku != blank -%}
"sku": {{ product.selected_or_first_available_variant.sku | json }},
{%- endif -%}
{%- endif %}
"brand": {
"@type": "Thing",
"name": {{ product.vendor | json }}
Expand Down

0 comments on commit 8e91deb

Please sign in to comment.