8 copy-paste Liquid snippets we ship in real themes: section schema, free-shipping bar, metafields with fallbacks, responsive images, sale and low-stock badges, SEO breadcrumbs and safe JSON for JavaScript. Every snippet follows Online Store 2.0 architecture. MIT licensed. By Oleh Stupak, CEO at Mgroup · Updated
Copy-paste Shopify Liquid code for Online Store 2.0 themes
Eight production patterns: a section skeleton with blocks and presets, a cart free-shipping bar, metafields with fallbacks, responsive images, sale and low-stock badges, SEO breadcrumbs with schema, and a safe product-to-JavaScript handoff. Filter by topic, copy, paste into your theme.
Online Store 2.0 section skeleton with blocks
sections/mg-feature-grid.liquidsectionstheme
Minimal section with settings, repeatable blocks and presets so it appears in the theme editor. Start every custom Shopify section from here.
Shows how much is left to unlock free shipping. Threshold is a theme setting in cents-aware currency; call it with {% render 'mg-shipping-bar', threshold: settings.free_shipping_threshold %}. A classic CRO win for AOV.
Renders a metafield only when the definition exists and has a value; falls back to a default. Works for single-line text, rich text and lists.
{%- comment -%} Single-line text or number {%- endcomment -%}{%- assign material = product.metafields.specs.material -%}{%- if material != blank -%}
<dt>Material</dt><dd>{{ material.value | escape }}</dd>
{%- else -%}
<dt>Material</dt><dd>See product description</dd>
{%- endif -%}{%- comment -%} Rich text (metafield_tag renders proper HTML) {%- endcomment -%}{%- if product.metafields.specs.care_guide != blank -%}
<div class="rte">{{ product.metafields.specs.care_guide | metafield_tag }}</div>
{%- endif -%}{%- comment -%} List of single-line text {%- endcomment -%}{%- if product.metafields.specs.features.value.size > 0 -%}
<ul>
{%- for feature in product.metafields.specs.features.value -%}
<li>{{ feature | escape }}</li>
{%- endfor -%}
</ul>
{%- endif -%}
Responsive image with srcset and lazy loading
snippets/mg-image.liquidperformancetheme
Uses image_url + image_tag so Shopify serves the right size per viewport; first-fold images get loading: eager and fetchpriority for better LCP. Part of every performance audit we run.
Computes the discount from compare_at_price for the selected variant and only renders when there is a real saving. Use money_without_trailing_zeros for cleaner prices.
Visible breadcrumbs plus matching structured data for product, collection, page and article templates. Uses the collection the customer came from when available. See our Shopify SEO services.
Emit variant data as JSON in a <script type="application/json"> tag instead of inline JS — safe against quotes, cacheable, and easy to read in your variant picker.
Liquid performance rules we follow in every snippet
No inline JavaScript in loops. Data goes into a single application/json script per section; behaviour lives in a deferred file.
Images via image_url + image_tag with explicit widths and sizes, lazy by default, eager with fetchpriority="high" only for the first-fold image — the single biggest LCP win on Shopify product pages.
Whitespace control ({%- and -%}) on every tag so the rendered HTML stays small and predictable.
Escape everything merchant-editable with | escape; use | json when handing values to JavaScript.
Guard metafields with != blank and check .value.size on lists so unset definitions never print empty markup.
Liquid is Shopify's open-source template language. Theme files combine HTML with Liquid objects ({{ product.title }}), tags ({% if %}, {% for %}) and filters (| money) that Shopify renders on the server before sending the page to the browser.
What is the difference between a Shopify section and a snippet?
Sections live in sections/, have a {% schema %} block and appear in the theme editor where merchants add, reorder and configure them. Snippets live in snippets/, are included with {% render %} and are reusable fragments with no editor settings of their own.
Are these snippets compatible with Online Store 2.0 themes?
Yes. They use current Shopify APIs — image_url and image_tag filters, metafield definitions, section schema with blocks and presets — and work in Dawn-based and custom Online Store 2.0 themes.
Can I use these Liquid snippets in a client project?
Yes. All snippets are MIT licensed. Test in a duplicate theme, rename classes to match your theme and keep an eye on Shopify's changelog for deprecated filters.
Do you build custom Shopify sections?
Yes. Custom Shopify sections and full theme development are core Mgroup services — every section ships with editor controls, schema docs and Core Web Vitals-safe markup.
Shopify Section Partner
Ready to give your editor real superpowers?
Talk to Mgroup about custom Shopify sections — designed for your brand, built on Online Store 2.0, easy to edit, and fast in production.