Multiple Variant Images
Different images for variants in the Horizon theme from Shopify (without apps and without Shopify Plus). A free solution from VecomLab.
Relevant for Horizon theme version 3.1.0

Problem description
By default, in the Shopify admin and in the Horizon theme settings, each variant can only be assigned one image — not several.
The platform partially solves this for stores on the Plus plan. You can also use third-party Shopify apps, but this is often unprofitable and inefficient: errors appear regularly and sometimes take months to fix via support.
You can solve this task using Metafields and Metaobjects for Variants and the theme code editor.
Idea
Each variant has a metafield
custom.variant_gallery(list of files).We treat as “owned” all images whose file name matches the stem from the metafield or starts with the stem +
_or-.On the server (Liquid) we pre-hide extra images for the first frame.
On the client (JS) we read the “variant → files” map and filter when the variant changes.
If none of the variants has the metafield — nothing changes, everything works as in the original theme.
What’s new: zoom and quick add
The zoom dialog is now also filtered by variant: both thumbnails and large images.
Mobile quick add (collection page modal): on mobile, the modal shows only one image — the featured image of the current variant (as in the standard Horizon), even if the variant has a whole series.
Step 1. Variant metafield (once per store)
Settings → Metafields and metaobjects → Variants → Add definition
Name: Variant Gallery
Namespace and key:
custom.variant_galleryType: File → List of files
Validations: Images only
Options: enable Storefront API access
Save
Why this way: this is the native way to link a variant with files in Shopify Files. The key matches what the code uses.
Step 2. File name convention
In Files, give each series of photos for a variant a common stem:
In the variant metafield attach one “anchor” file from the series (for example, ring-gold.jpg). The rest will be picked up automatically by the stem.
Step 3. Inserts in _product-media-gallery.liquid
Below is exactly what we added/changed, and why.
3.1. JSON map variant → files (server → front)
Insert before {%- if has_image_drop -%}:
Why: the front receives ready JSON without parsing the DOM. We immediately normalize URLs to the base file name.
3.2. Flags on <media-gallery>
In the tag attributes, next to data-presentation and style, add:
data-vg-ready="0"— anti-flicker: while the script is running, images are hidden (CSS below).data-initial-variant-id— optional, for debugging/analytics; the script itself takes the variant id from the form.
3.3. vg_list for the first render
Right after {{ block.shopify_attributes }}:
Why: we need to know the current variant’s file list on the server in order to pre-hide extra images even before JS runs (correct first frame).
3.4. Server-side pre-hide in slides (Carousel)
Before you compute class/style/attributes for each media:
Then add vg-prehide and display:none:
3.5. Unified set of data attributes on each slide
Before the block with attributes:
And replace the attributes block with options that inject {{- common_data_attrs -}} (for model / image / “no zoom”).
Before:
After:
Why: the front needs the image type and URL. data-vg-allow/data-vg-prehide help CSS before JS initializes.
3.6. Same logic — for the Grid
Inside <ul class="media-gallery__grid"> before each <li> repeat the prehide logic:
And in the Grid <li> replace class="" and style="" with:
Add data attributes:
3.7. Filtering inside the zoom dialog (Liquid)
Zoom thumbnails (1)
Inside the thumbnails block (buttons .dialog-thumbnails-list__thumbnail) add pre-hide logic, like we did for slides/grid:
In the <button> replace class="" and style="":
And add attributes:
Large zoomed frames (2)
For <li> inside .dialog-zoomed-gallery apply the same prehide check and the same data attributes.
Insert the check before <li>:
Replace class="" and style="" in <li>:
And add attributes:
Same idea: we ensure a “clean” first frame in zoom even before JS runs.
3.8. Client script and mini CSS (after </media-gallery>)
Script:
reads
#variant-galleries-json;if the product has no variants with the metafield → sets
data-vg-ready="1"and exits (changes nothing);otherwise filters
imageslides by the current variant; on variant change — repeats;at the end sets
data-vg-ready="1"(anti-flicker off).
CSS:
Why: completely removes “jitter/flicker” and intermediate states before everything is ready. We don’t touchthumbnails/arrows — in the “clean” version of this script we don’t even hide them.
Why this is needed:
while
data-vg-ready="0"is set, the modal doesn’t “flash” with a set of images;JS additionally guarantees that even after switching variants in the modal there will be exactly one image.
What we deliberately don’t touch (remains “as in the theme”)
We’ll do this in future script versions:
Counter / arrows / thumbnails of the carousel — we don’t configure or hide them with separate rules.
Small audit of “extra stuff”
data-initial-variant-id— optional, can be removed (won’t break the script).MutationObserveris currently attached todocument.bodyfor robustness with dynamic re-renders. You can narrow it to only watch<media-gallery>, but the current option is more reliable across themes/scripts.The duplicated logic “server-side pre-hide” + “client-side filter” is intentional: it gives an ideal first frame (no junk) and correct behavior on further switches. This is not redundant; it’s an anti-FOUC layer.
Result
If a variant has the Variant Gallery metafield filled in, only its images are shown on the page (by file name). If there is no metafield — everything works as before. The first frame is clean and without flickering (server pre-hide), and when switching variants the gallery is updated by the script. No apps, conflicts, or slowdowns.
Theme settings
The Product media (Grid + Hint) and Grid + Dots modes are supported. The “single image in Mobile quick add” behavior is enabled only inside the modal on screens ≤ 749 px; on the product page and on desktop you still have the full variant-based gallery.

FAQ
Last updated