Creating custom metafield definitions
If there's no standard metafield definition for the specialized information that you want to add to your Shopify store, then you can create a custom metafield definition. You also create custom definitions when you migrate existing metafields to a definition.
When you create a custom definition for a metafield, you specify the following information:
- namespace and key, for example, to group metafields for specific parts of your store
- content type, such as text, file, or URL
- validation rules, such as character limits, minimum and maximum values, or preset values
- description (optional), such as information about what values to enter for the metafield
- list of values (optional), which allows you to add multiple single line text or product reference values to your metafield list
Some content types have additional configuration options that you need to select. Configuration options can include the following:
- default units of measurement
- single-line or multi-line fields
- minimum and maximum values
- default currency
Using custom metafields with the Storefront API
If you want to allow custom storefronts to display your Metafields, then you can give access to the Storefront API when you create or edit a Metafield definition. You might want to give access to the Storefront API if you sell your Shopify products through a non-Shopify website, video game, or other custom shopping experience.
By default, values for custom metafields aren't accessible to custom storefronts. Learn more about using Metafields with the Storefront API.
Before you begin
Before you create a custom metafield definition, review the following information to make sure that you understand how to configure your definition:
Create a custom definition
- From your Shopify admin, go to Settings > Metafields.
- Select the part of your store that you want to add a metafield to. For example, Products.
- Click Add definition.
- In the Name field, enter a name for your definition, and then select the name that you entered from the list.
- Optional: In the Namespace and key field, edit the default identifier for your metafield.
- Optional: In the Description field, enter a description for your metafield values.
- Optional: To allow custom storefronts to display values for this metafield, select Give access to Storefront API requests.
- Click Select content type, and then select the content type that best matches your metafield from the list.
- Optional: To allow a list of values in your metafield, select Accept list of values.
- Configure the content type and validation information:
- If the content type has additional configuration options, then select the correct option for your metafield. For example, type of measurement.
- Optional: In the Validation section, configure the Additional rules to limit the range of accepted values.
- Optional: To change the content type or validation rules for your custom definition, click Change, and then select another content type from the list.
- Optional: Click Definition pinned to unpin the definition from the resource detail page.
- Click Save.
Next steps after adding metafield definitions
After you add definitions for your Metafields, you can do the following: