The Architecture of Theme App Embed Blocks (target: 'head')
Shopify Online Store 2.0 introduced Theme App Extensions to fundamentally solve the problem of app bloat. By specifying 'target': 'head' inside an app embed block's schema definition, developers can inject structured data directly into the theme layout without modifying a single line of theme.liquid.
Key Engineering Principles
{%- comment -%}
SchemaTool Online Store 2.0 App Embed Block
target: "head" | Zero Client-Side JavaScript
{%- endcomment -%}
{%- if request.page_type == 'product' -%}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Product",
"name": {{ product.title | json }},
"description": {{ product.description | strip_html | truncatewords: 60 | json }},
"image": {{ product.featured_image | image_url: width: 1200 | json }},
"sku": {{ product.selected_or_first_available_variant.sku | json }},
"brand": {
"@type": "Brand",
"name": {{ product.vendor | json }}
},
"offers": {
"@type": "Offer",
"priceCurrency": {{ cart.currency.iso_code | json }},
"price": {{ product.selected_or_first_available_variant.price | divided_by: 100.0 | json }},
"availability": "https://schema.org/{% if product.selected_or_first_available_variant.available %}InStock{% else %}OutOfStock{% endif %}",
"url": {{ shop.url | append: product.url | json }}
}
}
</script>
{%- endif -%}
{% schema %}
{
"name": "SchemaTool Structured Data",
"target": "head",
"settings": [
{
"type": "checkbox",
"id": "enable_product_schema",
"label": "Enable Product Structured Data",
"default": true
}
]
}
{% endschema %}