To create and display a metafield on a Shopify product, follow these steps. Shopify metafields let you store custom data for products, variants, collections, etc.
✅ Step 1: Create a Metafield Definition
-
Go to your Shopify Admin.
-
Navigate to Settings > Custom data > Products.
-
Click "Add definition".
-
Fill in:
-
Name: e.g., "Author"
-
Namespace and key: e.g.,
custom.author
-
Content type: Choose the appropriate type (e.g., "Single line text", "URL", etc.)
-
-
Choose whether it should appear in the product admin.
-
Click Save.
✅ Step 2: Add Metafield Value to a Product
-
Go to Products in the Shopify Admin.
-
Open any product.
-
Scroll down to the Metafields section at the bottom.
-
Enter the value for the field you created (e.g., "John Doe" for the Author).
-
Save the product.
✅ Step 3: Display the Metafield in the Theme
You’ll need to edit your theme files (via code) or use Online Store 2.0 features like dynamic sources in the theme editor.
Option A: Add via Theme Editor (OS 2.0 Themes)
-
Go to Online Store > Themes.
-
Click Customize on your current theme.
-
Navigate to the Product page.
-
Add a Text block or select an existing one.
-
Click the Dynamic source icon (the database-looking symbol).
-
Choose your metafield (e.g.,
Author
). -
Save.
Option B: Add via Code
-
Go to Online Store > Themes > Edit Code.
-
Open your product template (usually
sections/main-product.liquid
ortemplates/product.liquid
). -
Insert this where you want the metafield displayed:
-
Replace
custom.author
with your namespace.key. -
Use conditional logic to prevent empty output:
0 Comments