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

TL;DR
To add Shopify snippets, create a new .liquid file in your theme’s Snippets folder, add your reusable Liquid and HTML code, and insert it into templates or sections using the {% render %} tag. This modular approach helps reduce code duplication, improves theme maintainability, and makes Shopify development more scalable. Following best practices such as using descriptive file names, passing variables explicitly, and avoiding the deprecated {% include %} tag ensures cleaner, more efficient theme development.
Keep reading for a step-by-step guide to creating, rendering, and managing Shopify snippets effectively.
Introduction
If you’re leading a fast-moving Shopify storefront, you’re already familiar with this pain: bloated templates, repeated logic, cluttered markup, and the creeping cost of just one more quick fix.
Shopify gives you power, but without modular thinking, your theme becomes a liability.
This is where Shopify snippets come in, not as an optional nicety, but as a core architectural pattern. Snippets aren’t about DRY for the sake of it. They’re about making your codebase scalable, collaborative, and versionable across teams.
This guide isn’t just a tutorial. It’s a technical walkthrough designed for development teams, agency implementers, and tech-savvy store owners who want to build modular, stable, and modern Shopify themes using Liquid snippets the right way.
Let’s go beyond the basics on how to include snippets in Shopify.
What Are Shopify Snippets?
In Shopify, snippets are small, reusable files written in Liquid, Shopify’s templating language. It allows developers to modularize code, isolate logic, and reuse UI components across multiple templates and sections.
Snippets are stored in the snippets/ directory of your theme and always end with a .liquid extension. You can think of them as atomic pieces of markup and logic, used to keep your theme clean, fast, and maintainable.
What Makes Snippets in Shopify Essential?
- Isolation: Including snippets, Shopify allows you to encapsulate logic and UI in one place, great for separating concerns.
- Reusability: Once defined, they can be rendered across any part of your theme (product pages, collections, sections, layouts).
- Performance: Smaller files load faster. Less repetition means fewer opportunities for bugs.
- Team Scalability: Easier for multiple devs to work on distinct parts of the theme without stepping on each other’s code.
Think of Shopify snippets like React components or partials in MVC frameworks. They’re not full templates, but they do the heavy lifting inside them.
Using snippets to reduce template bloat results in smaller files and faster server response time. This is especially important as Shopify themes can exceed 500KB+ in non-modular builds. If your store is also exploring a fully decoupled setup, our guide on headless commerce covers how componentized architecture extends beyond Liquid into a separated frontend and backend.
How to Include Snippets in Shopify (The Right Way)?
To know how to add snippets in Shopify, keep in mind that Shopify isn’t just about dropping code into a file, it’s about creating a modular, reusable unit that can be safely injected across your theme with proper scope, performance, and maintainability in mind.
Step 1: Create the Snippet File
Go to your Shopify Admin. Navigate to: Online Store → Themes → Actions → Edit Code. In the left sidebar, scroll to the Snippets folder. Click Add a new snippet. Name it something descriptive (no spaces), for example: product-badge.liquid.

File location: snippets/product-badge.liquid
Step 2: Add Code Inside the Shopify Snippet
Now add your desired Liquid and HTML logic.
{% comment %} snippets/product-badge.liquid {% endcomment %}
{% 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
In any template, section, or another snippet, you can now call your snippet like this:
{% render 'product-badge' %}
Use {% render %} instead of {% include %}; include is deprecated and doesn’t scope variables properly.

Example: Injecting a Snippet into a Product Template
Inside sections/product-template.liquid or templates/product.liquid, insert:
<h1>{{ product.title }}</h1>
{% render 'product-badge' %}
<p>{{ product.description }}</p>
That’s it. Your snippet is now live and dynamic.
Best Practices for Including Snippets in Shopify
These tips will help you write cleaner, more performant, and collaboration-friendly Shopify themes using snippets the right way.

1. Use {% render %}, Never {% include %}
Shopify deprecated include in favor of render for good reason:
| Feature | {% render %} | {% include %} (deprecated) |
|---|---|---|
| Scope isolation | Yes | No (inherits parent scope) |
| Performance | Optimized | Slower |
| Shopify support | Recommended | Deprecated |
Always pass variables explicitly with render.
2. Keep Snippets Purposeful and Atomic
Each snippet should do one thing well:
- price-display.liquid handles price formatting
- trust-badges.liquid shows icons and labels
- b2b-logic.liquid handles B2B-specific conditions
Don’t dump multiple responsibilities into one snippet, split them up.
3. Use Descriptive Naming
Name snippets clearly so other devs instantly understand their purpose.
GOOD: product-sale-badge.liquid
BAD: psb.liquid
Use hyphens to separate words. Avoid spaces, uppercase letters, or abbreviations that aren’t universal across your team.
4. Pass Only What’s Needed
Avoid passing entire product or collection objects unless necessary.
Instead of this:
{% render 'product-tile', product: product %}
Prefer:
{% render 'product-tile', title: product.title, image: product.featured_image %}
Keeps the snippet scoped, predictable, and portable.
5. Use Defaults Inside Snippets
Snippets should be fault-tolerant:
{{ label | default: 'New' }}
{{ class | default: 'badge-default' }}
This prevents layout breaks if a variable isn’t passed.
6. Test Across Breakpoints
Shopify snippets often control critical UI blocks like:
- Buttons
- Price displays
- Ratings
- Payment icons
Test your snippet rendering on:
- Desktop
- Mobile
- Inside carousels/sliders
- With dynamic content loading
7. Don’t Use Snippets for Editable Content
If a merchant needs to edit text, images, or layout via the Theme Editor, use a section, not a snippet.
| Use a… | When you need… |
|---|---|
| Snippet | Static logic, reusable markup |
| Section | Dynamic content + schema, customizable via Theme Editor |
8. Document Your Snippets
If you work in a team, add a brief comment header in each snippet file:
{%- comment -%}
Snippet: discount-ribbon.liquid
Usage: Displays ribbon if product is on sale
Params: none
{%- endcomment -%}
This reduces ramp-up time for other devs.
9. Nest Responsibly
Snippets can call other snippets, but avoid deep nesting (more than 2 levels), and never call a snippet recursively, you’ll crash the theme.
10. Use Git and Versioning for Snippet Management
If your theme is under source control (which it should be), treat each snippet as a micro-component and encourage pull requests for new snippet additions. Use consistent file-level commit messages, such as “add: trust-badge snippet.”
Theme architecture choices like these compound over time. If you’re also evaluating whether your storefront needs to scale beyond Liquid entirely, it’s worth reading our breakdown of low-code development, which covers when modular, component-driven builds make more sense than a fully custom codebase.
Implementing snippets the right way takes more than copy-pasting code. If you’d rather focus on growing your store while experts handle the technical details, our Shopify developers are ready to help.
Hire Dedicated Shopify Developers
To Wrap It Up!
Learning how to include snippets in Shopify isn’t just a dev checklist item, it’s a mindset shift. When you start thinking in snippets, you’re not just writing code, you’re building a modular, scalable system your entire team can grow with. It’s how you future-proof a theme and keep your storefront fast, clean, and easy to iterate on.
- For solo developers, this means cleaner logic.
- For tech teams, it means clearer ownership and fewer conflicts.
- And for scaling businesses, it means less time firefighting broken templates and more time shipping actual improvements.
If you are looking to fulfill it, connect with us at Enstacked for e-commerce development services. To know more about us, and how we can help you and beyond, connect with us to hire dedicated developers who can help you with the same.
If you need a team that understands your storefront inside-out, from dev workflows to business outcomes, we’re here to plug in where you need us.
Book a Free Consultation Call Today
Frequently Asked Questions (FAQs)
What is the difference between a snippet and a section in Shopify?
A snippet is a small, reusable block of Liquid code used for logic or UI elements, while a section is a larger, editable block that can include schema and be customized through the Theme Editor.
How do I add markup on Shopify?
Go to Themes → Edit Code, open a section, template, or snippet file, and paste your HTML or Liquid markup where needed in the layout.
Where should I paste the FAQ schema snippet in my blog template?
To include a snippet in Shopify, paste the FAQ schema inside a script tag with type “application/ld+json” at the bottom of your article.liquid or main-article.liquid file, right after the blog content.
What common mistakes should I avoid when adding snippets?
Avoid using {% include %}, forgetting to pass variables, using unclear file names, or putting editable content in snippets instead of sections.
How do I include JSON-LD FAQ schema in my Shopify blog for rich snippets?
Wrap your schema in a script tag with type “application/ld+json” and include the snippet in Shopify below your blog content. Match the questions with visible FAQs on the page.
How do I create and insert a custom snippet in a blog post?
Create a snippet (e.g., faq-block.liquid), add your code, then use {% render ‘faq-block’ %} inside the blog template to insert it.



