Elevate Your Shopify Store: Autoplay Product Videos Directly on Collection Pages

Hey everyone! I was just digging through some of the community discussions the other day and stumbled upon a really common, yet super impactful, question from a store owner named Celinajes. It's something many of us have pondered: how do you get product videos to autoplay right on your collection pages, instead of just showing a static thumbnail?

Celinajes, using the Horizon theme, laid out exactly what they wanted: muted, looping, inline videos playing automatically in the product grid, with the option for customers to click to unmute, and importantly, per-product control. It's a fantastic idea, really, because it brings so much more life and interactivity to those crucial first impressions on a collection page. Static images are great, but a dynamic video can showcase a product's features, texture, or usage in a way a photo simply can't.

The good news is, the community delivered! While devcoders initially asked for more details to provide a tailored solution (which is always a smart first step when troubleshooting!), @EcomBridge_Solutions came in with a really solid, actionable code snippet that addresses Celinajes's request beautifully. It's a prime example of how powerful the Shopify community can be!

Before we dive into the nitty-gritty, a quick but crucial reminder: always, always, ALWAYS back up your theme before making any code changes. Just head to Online Store > Themes, find your current theme, click the '...' button, and select 'Duplicate'. Better safe than sorry, right?

Step-by-Step Implementation: Bringing Your Product Videos to Life

This solution involves tweaking a couple of theme files and setting up a metafield. It's a bit of code, but I'll walk you through it.

1. Modify card-product.liquid for Video Display

This file is responsible for how individual product cards look on your collection pages. We're going to tell it to check if the first media for a product is a video and, if so, display it instead of an image, with our desired autoplay behavior.

In your Shopify admin, go to Online Store > Themes. Find your current theme, click Actions > Edit code. Open the file sections/card-product.liquid (or it might be in `snippets/card-product.liquid` depending on your theme structure, but `sections/card-product.liquid` is common for newer themes like Dawn/Horizon).

Look for where the first media image renders. It often looks something like {{- product.media[0] | image_url: width: 533 | image_tag -}} or similar. You'll replace that line with this conditional logic:

{% if product.metafields.custom.autoplay_video == true and product.media[0].media_type == 'video' %}
  
{% else %}
  {{- product.media[0] | image_url: width: 533 | image_tag -}}
{% endif %}

What this code does:

  • It first checks two things: if you've enabled the `autoplay_video` metafield for this specific product (we'll set that up next) AND if the very first media item for that product is actually a video.
  • If both are true, it renders an HTML tag. The autoplay, muted, loop, and playsinline attributes are crucial here. playsinline is especially important for mobile browsers to allow videos to play directly within the page layout rather than going full screen.
  • If either condition is false (no metafield or first media isn't a video), it falls back to displaying the standard product image.

Important: The original solution provided by EcomBridge_Solutions was a bit more condensed. I've expanded it slightly to explicitly include the tag and its attributes directly within the `if` block, which is generally how you'd implement the desired autoplay, muted, looping, and inline behavior. The original snippet was a good starting point for the conditional logic, and this expands on it for full functionality.

2. Add JavaScript for Click-to-Unmute

Celinajes also wanted the ability for customers to click or tap the video to unmute it. This requires a little bit of JavaScript.

In your theme code editor, open assets/global.js. Scroll to the very bottom of the file and add this:

document.querySelectorAll('.card-product__video').forEach(video => {
  video.addEventListener('click', () => { video.muted = !video.muted; });
});

This small script is quite elegant! It finds all video elements that have the class `card-product__video` (which we added in the previous step) and attaches an event listener to each. When a user clicks on one of these videos, it simply toggles the `muted` property, effectively unmuting or re-muting the video.

3. Enable Per-Product Control with Metafields

The final piece of the puzzle is having that per-product control. This is where @EcomBridge_Solutions's suggestion of using a boolean metafield comes in handy.

Go to your Shopify admin Settings > Custom data > Products.

  • Click Add definition.
  • For the Name, you could put something like "Autoplay Video on Collection Page."
  • The Namespace and key should be custom.autoplay_video. This is critical as it matches the code we just added.
  • For the Content type, select Boolean. This gives you a simple checkbox.
  • Save the metafield definition.

Now, when you edit any product in your Shopify admin, you'll find this new "Autoplay Video on Collection Page" option under the "Metafields" section. Simply check the box for any product where you want its first media video to autoplay on collection pages!

Important Considerations for a Smooth Experience

While this is a fantastic enhancement, remember a few things:

  • Performance: Videos are heavier than images. While muted autoplay is generally well-optimized by browsers, having many videos playing simultaneously on a collection page could impact load times, especially on slower connections or older devices. Test thoroughly!
  • User Experience: Muted autoplay is usually the best practice. Unexpected sound can be jarring. Giving users the option to unmute is key, and our JavaScript takes care of that.
  • Theme Compatibility: This solution is pretty generic for Dawn-based themes (like Horizon), but if you're on a very old or heavily customized theme, the file names or exact locations for media rendering might differ slightly. The core logic, however, should remain similar.

This kind of dynamic display truly elevates the shopping experience, giving customers a richer, more engaging way to discover your products right from the get-go. A big shout-out to Celinajes for asking the question and EcomBridge_Solutions for sharing such a clear and effective solution with the community!

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases