To create metafields in Shopify, you need three steps: a definition that tells Shopify what kind of information is stored, a value for each product, and a place in the theme where the value appears. What metafields and metaobjects can do in general is described on the page Shopify metafields and metaobjects. This guide walks you through the setup using care instructions as an example.
Requirements
- Access to the Shopify admin with access to products, settings and themes
- at least one created product
- a theme whose sections support dynamic sources
- a clear idea of which information you want to store and in what form: free text, number, date, file or a fixed selection
Create a metafield definition in Shopify
-
Open a product. In the Shopify admin, go to Products and open any product.
-
Add a definition. In the Product metafields section, click Add definition.
“Product metafields” section on the product with “Add definition” -
Enter a name. In the Name field, enter a label, for example “Care instructions”. If Shopify shows a matching standard definition below, you can accept it.
-
Check namespace and key. Shopify generates a unique identifier from the name, such as
custom.care_instructions. You can adjust it in the Namespace and key field. -
Select a type. Click Select type and choose the type that fits the information, for example Single line text. If several values should be possible, click One value and choose List of values.
-
Add a description and rules. Under Add description, enter a note for everyone who fills in the field later. If the Validation section appears, use it to restrict the allowed values, for example the number of characters.
-
Save. Click Save.
The definition applies to all products, not just the one you opened. Alternatively, you can create definitions under Settings > Custom data.
Enter a value on the product
- Open the product. Under Products, open the product that should get a value.
- Find the metafield. In the Metafields section, the definitions appear as a list. If your field does not appear there, click Show all; only pinned metafields are shown automatically.
- Enter the value. Click + Add next to the field and enter the text.
- Save. Click Save.
For many products at once, bulk editing is a good fit.
Show the metafield in your theme
The value is now saved, but not yet visible in the store. To change that, you connect it to a setting in the theme editor. Shopify calls this connection a dynamic source.
- Open the theme editor. Go to Online Store and click Customize next to the theme you want.
- Choose the product template. The editor first shows the home page. Use the Home page dropdown to select the product template.
- Add or select a block. Add a block that displays text to the section with the product information, or click an existing one in the sidebar.
- Connect a dynamic source. In the block’s text setting, click the icon for connecting a dynamic source, three stacked discs to the right of the field, and select your metafield from the list. The selection has a search.
- Save. Click Save and check the product page in the store.
A text setting can hold several dynamic sources, so you can mix your own text and the metafield, for example “Care:” followed by the value. Up to 50 dynamic sources per text setting and up to 100 per template are possible.
If your theme does not support dynamic sources at the place you want, the route through the theme code remains. This requires programming skills.
Common mistakes
- Edited the wrong template. If your products use several templates, the metafield appears only where you connected it.
- Free text instead of a fixed selection. For information with only a few possible values, a list is cleaner than text that everyone writes differently.
- Field not pinned. If you cannot see the metafield on the product, you may think it was deleted. It is under Show all.
- Standard definition overlooked. Ready-made definitions exist for common information. Custom fields with the same purpose mean maintaining things twice.
- Did not check a product without a value. After connecting, also look at a product where the field is empty.
- Did not check mobile. Additional blocks lengthen the product page. Check the view on a smartphone.
Help with metafields
If individual fields are meant to grow into a whole data structure for theme, filters and interfaces, we plan it with you: Shopify metafields and metaobjects.