Metafields are custom fields a store adds to its products, variants, collections, categories, pages, blog posts, blog categories, vendors, brands and the store itself. Fields marked visible on the storefront are available to sections.
Read metafields#
Read them under .metafields.<namespace>.<key> on any item that has them, and on shop for the store's own fields:
{% assign specs = product.metafields.specs %}
{% if specs.material %}
<dl class="specs">
<dt>{{ "specs.material" | t }}</dt>
<dd>{{ specs.material }}</dd>
</dl>
{% endif %}
<p>{{ shop.metafields.brand.tagline }}</p>
Values arrive ready to use: numbers as numbers, lists as lists, choices as their labels in the shopper's language when translation is enabled, files as media objects, and product/variant references as visible cards. Reference resolution is batched across detail and listing contexts, capped at 256 distinct product/variant references per request and one level deep. Unavailable or over-budget references are absent; lists omit them. Check that a value is present before printing it. See CTX: Metafields for types, translation fallback and resolution limits.
{% assign pair = product.metafields.merch.pairs_with %}
{% if pair %}
<a href="{{ pair.url }}">{{ pair.title }} · {{ pair.price.current | money }}</a>
{% endif %}
A referenced product that is not available on the storefront reads as nothing.
Declare the fields your theme needs#
Declare the metafields your theme reads in config/metafields.json, as rule metafields.declared of the theme contract requires. The file looks like this:
[
{ "owner_type": "product", "namespace": "specs", "key": "material",
"type": "string", "name": "Material", "translatable": true },
{ "owner_type": "product", "namespace": "specs", "key": "fit",
"type": "single_select", "name": "Fit",
"choices": [ { "key": "slim", "label": "Slim" }, { "key": "regular", "label": "Regular" } ] }
]
Field |
Meaning |
|---|---|
|
|
|
The field's address: |
|
The field type, such as |
|
The name merchants see, up to 100 characters. |
|
Optional help text. |
|
For |
|
For text and choice types: merchants can translate the values. |
|
For |
A theme can declare up to 40 fields. If the store already has a field with the same address but a different type, installation stops and names the field. A Theme Store update creates the fields its new version adds; the update preview lists them under metafield_definitions_added, and a type clash stops the update the same way. Existing definitions and values are never changed, and uninstalling a theme or undoing an update never deletes metafield values.
Platform metafield block#
Merchants show a metafield without theme code by adding the platform's Metafield block (theme:metafield) in the theme editor or with a connected AI tool (Store MCP add_block). Every theme has it: any section that accepts app blocks (accept_app_blocks) or theme blocks (accept_theme_blocks) and renders {% blocks %} takes it, whatever its theme_blocks list says. The storefront writes its markup for every value type; your theme only styles it.
<div class="tf-metafield tf-metafield--string" data-tf-metafield="specs.material">
<span class="tf-metafield__label">Material</span>
<div class="tf-metafield__value"><span class="tf-metafield__text">Organic linen</span></div>
</div>
Value type |
Markup inside tf-metafield__value |
|---|---|
text, choices |
|
integer, decimal |
|
date, datetime |
|
boolean |
|
url |
|
file |
|
product, variant, page, blog post, collection and custom content references |
|
rich_text |
|
color |
|
json |
|
list.* |
|
The block's wrapper also carries tf-metafield--<type> (dots and underscores as hyphens, for example tf-metafield--list-file-reference), so you can style each type. Its settings: Show a field of (owner: product, collection, category, vendor, brand, page, blog_post or store), the field (field_<owner>, a storefront-visible definition of that owner as namespace.key), Label and Show label. The owner is the page's own item of that type; on a product page vendor, brand and category are the product's (its first category). store works on every page.
The label is the definition's name, translated per storefront language (definition name translations in Store Admin, translation CSV or the Store API), unless the merchant writes a label in the block; that label is theme text, translated with the theme's text translations. An empty value renders nothing for shoppers. In the theme editor the block says why it is empty: no field chosen, no such owner on the page, a field that is not storefront visible, or no value.
Theme contract rule metafields.block: the section that shows the page's item (on a product, collection, category, vendor, brand, page or blog post template, the first section reading that item) must accept blocks so merchants can place the Metafield block there. The metafield-block check warns when it does not.
If your theme has its own block that shows a picked metafield, retire it for the platform block with a rename_block migration to theme:metafield: a renamed instance's field setting becomes the product field (field_product), and its label is kept, a theme string (@t:) included. List the old block's defaults in source_defaults so instances that never saved them keep what they showed.
"migrations": [
{ "id": "custom-field-to-platform-metafield", "op": "rename_block",
"from_type": "custom_field", "to_type": "theme:metafield",
"source_defaults": { "field": "details.material", "label": "@t:sections.main_product.custom_field.label" } }
]
Use metafields elsewhere#
- Connect a text setting to a metafield in the editor: see dynamic sources.
- Filterable metafields appear as filters on product listings.