Elevate Your Shopify Collection Pages: Autoplay Videos in Product Grids
Hey store owners!
You know how crucial product visuals are, right? High-quality images are a given, but videos? They take things to a whole new level, offering dynamic engagement that static pictures just can't match. We often see fantastic videos on individual product pages, but what if you could bring that dynamism directly to your collection pages, right in the product grid?
That's exactly what Celinajes, from the awesome store Namiso.dk, was asking in a recent community thread. They were looking for a way to customize their Shopify product cards on collection pages, specifically with the Horizon theme, to display videos instead of static images. The dream? Autoplay, muted, looping, inline videos as the primary media, with an option to unmute on click, all controllable on a per-product basis. Sounds pretty powerful, doesn't it?
![]()
It's a brilliant idea, and thankfully, the community stepped up with a really clever solution. While devcoders initially offered to dive deep into Celinajes's specific store setup, EcomBridge_Solutions came in with a detailed code-based approach that tackles all of Celinajes's requests. This kind of collaborative problem-solving is what makes the Shopify community so special!
Why Autoplaying Videos on Collection Pages?
Before we dive into the 'how,' let's quickly chat about the 'why.' Imagine a customer browsing your collection. Instead of just scrolling past static images, they see a short, engaging video clip instantly showcasing your product's key features, how it's used, or its unique texture.
- Instant Engagement: Videos grab attention immediately.
- Quick Understanding: Show, don't just tell. A 5-second video can convey more than several images.
- Differentiate Your Store: Stand out from competitors still relying solely on static images.
- Improved UX: When done right (muted autoplay, easy unmute), it enhances the browsing experience.
The Community's Solution: Dynamic Product Cards with Video
The core of the solution involves a few key pieces working together: a custom metafield for per-product control, a Liquid code modification in your product card snippet to render the video, and a touch of JavaScript to handle the mute/unmute functionality. It's a robust approach that gives you full control.
Here’s how you can implement this on your own Shopify store, drawing directly from the insights shared in the community thread. Remember to always back up your theme before making any code changes!
Step 1: Set Up Your Product Metafield
This metafield will be your toggle switch to decide which products get the video treatment on collection pages.
- From your Shopify admin, navigate to Settings → Custom data.
- Click on Products.
- Click the Add definition button.
-
Fill in the details:
- Name: Something descriptive like "Autoplay Video on Collection"
- Namespace and key:
custom.autoplay_video(this is crucial for the code to work!) - Description (Optional): "Enable autoplay video on collection pages if first media is video."
- Content type: Select Boolean.
- Ensure "One value" is selected.
- Click Save.
Now, when you edit a product, you'll see a checkbox under the 'Metafields' section to enable or disable this feature for that specific product.
Step 2: Modify Your card-product.liquid File
This is where the magic happens in terms of displaying the video. You'll need to find the file responsible for rendering individual product cards. In many themes, including Horizon, this is often named something like card-product.liquid or product-card.liquid, usually found in the snippets or sections directory.
- From your Shopify admin, go to Online Store → Themes.
- Find your current theme and click Actions → Edit code.
- In the file explorer, search for
card-product.liquid(or similar, depending on your theme's structure). -
Inside
card-product.liquid, you'll need to locate the part of the code that renders the product's first media image. This usually looks something like{{- product.media[0] | image_url: width: 533 | image_tag -}}or similar. Once you find it, 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 %}A quick note on the code: The original community suggestion gave us the
if/elsestructure, but it didn't explicitly include the video tag for theifblock. Based on Celinajes's request for autoplay, muted, looping, and inline playback, I've filled in the video tag with those attributes. Theclass="card-product__video"is super important for our next step! - Click Save.
Step 3: Add JavaScript for Mute/Unmute Functionality
Now that your videos can autoplay, let's give customers the option to hear the sound, just as Celinajes requested! This JavaScript snippet will allow visitors to click (or tap) the video to toggle the mute state.
- In the same theme code editor, search for
assets/global.js(or a similar main JavaScript file liketheme.jsorcustom.js). -
Scroll to the very bottom of the file and add this code:
document.querySelectorAll(‘.card-product__video’).forEach(video => { video.addEventListener(‘click’, () => { video.muted = !video.muted; }); });This code looks for all elements with the class
card-product__video(which we added in the previous step) and attaches a click event listener. When clicked, it simply toggles themutedproperty of the video. - Click Save.
Step 4: Enable Videos for Your Products
Finally, it's time to put your new functionality to use!
- Go to any product in your Shopify admin.
- Scroll down to the Metafields section.
- Find your "Autoplay Video on Collection" metafield and check the box to enable it for that product.
- Ensure the product's first media (the very first image/video you uploaded) is indeed a video.
- Click Save.
Now, head over to your collection page where that product is displayed, and you should see your video playing beautifully!
Important Considerations for a Smooth Experience
Implementing dynamic features like this is fantastic, but a few things are worth keeping in mind:
- Video Optimization: Videos can be heavy. Ensure your product videos are optimized for web – compressed, short, and to the point – to prevent slowing down your collection pages. Shopify handles some optimization, but always start with a good source file.
- First Media is Key: This solution relies on the video being the first media item in your product's media gallery. If it's not, the code will default to showing the image.
- Accessibility: While autoplaying muted video is generally acceptable, always think about users with different needs. The click-to-unmute is a good step.
-
Theme Compatibility: This solution was discussed in the context of the Horizon theme, but the principles are widely applicable to most Shopify 2.0 themes. The exact Liquid file name might vary (e.g.,
product-card.liquid,media-card.liquid), but the core logic remains the same.
There you have it! A really engaging way to bring your product collections to life, thanks to a great question from Celinajes and a solid solution from EcomBridge_Solutions in the Shopify community. It's a fantastic example of how a small code tweak can make a big impact on your store's user experience and visual appeal. Give it a try, experiment with your product videos, and see how your customers respond!