February 19, 2025

The Easy Way to Create a Size Chart Metafield in Shopify

Arrow pointing left
back to blog

about

Learn how to create a size chart Metafield using the Shopify Admin, as well as how to create a size chart within Shogun.

the author

Adam Ritchie
Ecommerce Contributor

share this post

Every time one of your customers returns an order, you can expect to lose about $30 on average. This is due to all the time and money it takes to have items sent back to you, restock them, and then ship them out again. In total, the cost of online returns now exceeds $200 billion per year in the United States.

Want to reduce this expense? Try adding size charts to your Shopify store.

Indeed, a recent survey found that whenever an order is returned, 75% of the time it’s at least partly because the item doesn’t fit. Size charts will help prevent this from happening, leading to fewer returns (and, therefore, fewer expenses) that you need to deal with. 

Below, we’ll show you multiple ways to implement this feature:

Quickly create whatever you need for your Shopify storeWith Shogun’s visual editor, it’s easy to build your own custom ecommerce content.Get started now

Creating a Size Chart Metafield Using the Shopify Admin

For the most common types of product information, such as titles, prices, and descriptions, Shopify themes will typically provide pre-built fields that allow you to simply plug in whatever information you want to display.  

But that’s not the case for everything. Sometimes, you may not be able to find a field already available for a particular piece of product data that you need to show to your customers. For example, most themes don’t offer any such field for size charts.

Thankfully, Shopify has a feature called metafields that gives you the ability to create your own custom fields for your storefront.

There are a fair number of steps involved in setting up a size chart with a metafield on Shopify, but don’t worry — we’ll walk you through every part of the process. First, you need to add a new metafield definition, which will specify what part of your store the metafield applies to and what values it can have:

  • Log in to your Shopify account and select the “Settings” option in the left sidebar of the main control panel.
  • Select “Custom data”.
  • In the “Metafield definitions” section of this settings page, select “Products”. 
  • Click on the “Add definition” button. 
  • You’ll need to add a name as well as a namespace and key for your new metafield definition. For this example, we’ll be using “custom.size_chart” as the namespace and key. Also, click on the “Select type” option — then choose “File”, select “Accept specific file types”, and configure the settings so that only image files are accepted. Once you’re done, save your changes.
Every metafield definition needs a name, namespace, and key.

You can now add an image of a size chart to each product that needs it through the Shopify admin:

  • Select the “Products” option in the left sidebar of the main Shopify control panel.
  • Select the product that you would like to add a size chart to.
  • Scroll down to the “Product metafields” section of the product settings page and select the “Size Chart” option that you just set up.
  • Click on the “Select Image” button.
  • Add the image of your size chart for the product, then select “Done”. 
  • Save your changes to the product settings.
Upload an image of your size chart to the product settings page.

Finally, you’ll need to use a bit of Shopify Liquid code in order to get your size chart to actually show up:

  • Select the sales channel you want to customize in the left sidebar of the main Shopify control panel.
  • Click on the “Customize” button next to your theme — this will open up Shopify’s built-in theme editor. 
  • There’s a dropdown menu located near the top of the screen that will allow you to toggle between the different page templates in your theme — use this to navigate to the template that applies to your product pages (in most cases, this will be the “Default product” template).
  • Add a block or section wherever you would like your size chart to be located, and select the “Custom liquid” option for this new block/section. 
Add a new block or section for your Liquid code.

Here’s the code that you will need to insert into the “Custom liquid” field:


{% if product.metafields.custom.size_chart.value != blank %}{{ product.metafields.custom.size_chart | image_url: width: 350 | image_tag  }} {% endif %}

Take note of how the namespace and key of “custom.size_chart” are referenced in this code — if you used a different namespace and key for your size chart metafield, you’ll need to edit the code accordingly. Also, you may need to adjust the “width” part of your code for the desired size of your image. 

The beauty of this particular piece of code is that, with the help of the “if” statement, your new size chart section will only show up if you have uploaded a size chart for a product. That means there won’t be any awkward blank fields on your site — if a size chart doesn’t exist for a product, the entire size chart section will automatically be removed. 

Your size chart will be displayed on the live version of your product page once you’ve added the necessary Liquid code.

Creating a Size Chart Using Shogun Custom Elements and CMS Collections

The previous section went over how to add images of size charts to your Shopify store. 

What if you want to custom-code your size charts instead?

In that case, you will likely find Shogun’s Custom Elements and CMS Collections features to be quite useful.

CMS Collections allow you to build your own custom data models for your Shopify store. To create a CMS Collection for size chart data:

  • After downloading and installing Shogun, select the “Apps” option in the left sidebar of the main Shopify dashboard. 
  • Open Shogun.
  • Select the “Developer tools” option in the left sidebar of the Shogun control panel, then select “CMS”.
  • Click on the “Create New…” button. 

Enter a name for your collection, then use properties to define each individual item in the collection. For example, to create a CMS Collection for a jacket’s size chart, you could create a “Plain Text” property for each of the chest, sleeve, and waist measurements for your small, medium, and large sizes. 

CMS Collections allow you to build your own custom data models for your Shopify store.

Once your CMS Collection has been created, go back to the “CMS” section of the Shogun app and select the new collection. Then, click on the “Add entry” button to enter your data for each property.

Once you’ve created properties for your CMS Collection, you’ll then need to add the corresponding data for each property.

CMS Collections make it easy to keep track of all the different types of data that you’re displaying on your store. Also, they make the process of updating content much more efficient. Whenever you make a change to the data, this update will automatically be reflected on every page where the CMS Collection is deployed — that means there’s no need to go in and edit every single page that features your size chart manually.

Let’s now go over how you can use a CMS Collection to help build a customer-facing feature for your storefront. This is done by combining your CMS Collection with a Custom Element. 

Shogun offers a wide range of pre-built, customizable elements that you can add to your Shopify pages with just a couple clicks. But despite the variety of pre-built elements available, you sometimes might not be able to find exactly what you want for your store. In that case, you can use the Custom Elements feature to add your own code whenever you feel the need to do so. And CMS Collections can be assigned to variables in the code for your Custom Element.

To create a Custom Element based on the CMS Collection you just built for your size chart:

  • Go to the “Developer tools” section of the Shogun app, then select “Custom elements”.
  • Click on the “Create new” button.
  • You can add Liquid/HTML, CSS, and JavaScript code to create your new custom element. Whenever you create a variable, you’ll see a “Collection” option open up in the right sidebar of the code editor — use the “Which collection?” dropdown menu to select the CMS Collection for your size chart. 
  • Once you’re done writing your code, save your changes. 
CMS Collections can be referenced in the code for your Custom Elements.

For reference, we added the following Liquid/HTML code for this example:


<h1>Size Chart</h1>

<table class="sizeChart" border="0" cellpadding="10" cellspacing="0" width="100%">

<thead>

  <tr>

    <td></td>

    <td>Small</td>

    <td>Medium</td>

    <td>Large</td>

  </tr>

</thead>

<tbody>

<tr>

<td>Chest</td>

<td>{{jacket.small_chest}}</td>

<td>{{jacket.medium_chest}}</td>

<td>{{jacket.large_chest}}</td> 

</tr>

<tr>

<td>Sleeve</td>

<td>{{jacket.small_sleeve}}</td>

<td>{{jacket.medium_sleeve}}</td>

<td>{{jacket.large_sleeve}}</td>

</tr>

<tr>

<td>Waist</td>

<td>{{jacket.small_waist}}</td>

<td>{{jacket.medium_waist}}</td>

<td>{{jacket.large_waist}}</td>

</tr>

</tbody>

</table>

As you can see, properties can be referenced in your code using the following format: {{collection_name.property_name}}

We also added some CSS code to spruce up the styling:


.sizeChart{

  color: #10173A;

  font-weight: 700;

  text-transform: uppercase;

}

.sizeChart thead{

  background: #10173A;

  color: #f16021;

}

.sizeChart tr:nth-child(even){

  background: #777C8C; 

}

.sizeChart tbody tr td:first-child{

  font-size: 20px;

}

Once your Custom Element has been saved, you’ll be able to access it in Shogun’s visual editor:

  • Select the “Pages” option in the left sidebar of the main Shogun dashboard.
  • Use the page type filter or search bar (or simply scroll down) to find the page you would like to add your size chart to, then click on it — this will open the page in Shogun’s visual editor. 
  • Select the “Elements” icon in the left sidebar of the visual editor to open the element library.
  • Scroll down to the “Custom” section, click and hold on your new size chart element, and drag it over to wherever you want the element to be located on the page. 
  • In the customization settings for the element, select the data from your CMS Collection for the size chart.
Custom Elements can be accessed in Shogun’s visual editor.

The live version of the page will always display the most recent size chart data from your CMS Collection.

The Custom Element displayed on the live version of the page will show the most recent size chart data from your CMS Collection.

Creating a One-Off Size Chart for a Particular Product Page Using Shogun

As mentioned above, Shogun offers plenty of pre-built elements for easy ecommerce content creation. If you’d prefer, you can certainly use these tools to build a size chart instead of uploading an image or messing with any code. 

First, you’ll need to import the page you want to edit from Shopify into Shogun:

  • Go to the “Pages” section of the Shogun app.
  • Hover your cursor over the “Build or edit a page” option, then select “Import a page”. 
  • Click the “Import page” button next to the page you want to import.
  • Choose between the three import formatting options, then click on the “Import” button.
It only takes a few steps to import pages from Shopify into Shogun.

You can now use Shogun’s visual editor to make your edits to the page:

  • Go back to the “Pages” section of the Shogun app and select the page you just imported.
  • Click on the “Elements” icon in the left sidebar to open up the element library.
  • Of all the options available here, the “Table” element makes the most sense for a size chart. Click and hold on the icon for the “Table” element, then drag it to the place on the page where you want your size chart to be located.
  • As with each other element, there are myriad ways to customize your table. You can choose from hundreds of fonts for the header, change the background color of each cell, adjust the spacing of the rows and columns right down to the exact pixel, and much more. Drag the type of element you want to use into each cell of the table — while the “Text” element is the most obvious choice, you also have the opportunity to get more creative here. 
The “Table” element allows you to design your own size chart. 

After adding the table for your size chart, save and publish your changes to the page. 

Shogun’s visual editor gives you complete control over the look of your Shopify store.

With Shogun, you can quickly whip up size charts for any product page that needs it, helping you achieve a higher conversion rate and ultimately generate more sales.

Quickly create whatever you need for your Shopify storeWith Shogun’s visual editor, it’s easy to build your own custom ecommerce content.Get started now

You might also enjoy

Get started for free

Get hands on with everything you need to grow your business with a comprehensive suite of tools.
Start now
Arrow pointing up and to the right Arrow pointing up and to the right