How to Add Snippets in Shopify? The Step-by-Step Guide

Want to speed up your Shopify theme edits? Learn how to add snippets the right way with this quick, step-by-step guide cleaner code, faster updates
How to Add Snippets in Shopify

Table of Contents

Introduction

What Are Snippets in Shopify?

What Are Snippets in Shopify?

What Makes Snippets in Shopify Essential?

What Makes Snippets in Shopify Essential

How to Include Snippets in Shopify (The Right Way)?

Step 1: Create the Snippet File

Creating a new Liquid snippet file in Shopify theme editor under the Snippets folder

Step 2: Add Code Inside the Snippet

Adding Liquid conditional logic to Shopify snippet file for a product sale badge
      <!-- snippets/product-badge.liquid -->
{% if product.compare_at_price > product.price %}
  <span class="product-badge sale">On Sale</span>
{% endif %}

    

You can also pass data into this snippet (we’ll cover that in a bit).

Step 3: Render the Snippet in a Template or Section

Rendering a custom Shopify snippet inside the main-product.liquid template using

In any template, section, or another snippet, you can now call your snippet like this:

liquid

      {% render 'product-badge' %}
    

Example: Injecting Snippet into a Product Template

      <h1>{{ product.title }}</h1>
{% render 'product-badge' %}
<p>{{ product.description }}</p>
    

10 Best Practices for Including Snippets in Shopify

Best Practices for Including Snippets in Shopify

1: Use {% render %} — Never {% include %}

Feature{% render %}{% include %}(deprecated)
Scope isolationYesNo (inherits parent scope)
PerformanceOptimizedSlower
Shopify supportRecommendedDeprecated

2: Keep Snippets Purposeful & Atomic

3: Use Descriptive Naming

      GOOD:  product-sale-badge.liquid
BAD:   psb.liquid

    

4: Pass Only What’s Needed

      {% render 'product-tile', product: product %}

    
      {% render 'product-tile', title: product.title, image: product.featured_image %}
    

5: Use Defaults Inside Snippets

      {{ label | default: 'New' }}
{{ class | default: 'badge-default' }}

    

6: Use Defaults Inside Snippets

7: Use Defaults Inside Snippets

Use a…When you need…
SnippetStatic logic, reusable markup
SectionDynamic content + schema
Shopify supportRecommended

8: Document Your Snippets

      {%- comment -%}
/*
  Snippet: discount-ribbon.liquid
  Usage: Displays ribbon if product is on sale
  Params: none
*/
{%- endcomment -%}

    

9: Nest Responsibly

10: Use Git + Versioning for Snippet Management

To Wrap it Up!

Gaurav Jat

Published on July 8, 2025