Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi everyone
I'm struggling with this problem, seems like only I have it.
I chose a main Picture for my product, but instead of showing it in the product page , it defaults back to the first variant image upon entrance for some reason.
I realized it has something to do with this line of code:
{%- assign featured_media = product.selected_or_first_available_variant.featured_media -%}
But as I lack coding knowledge, I have no idea what to do with it. Everything I try gives back an error or deletes the whole thumbnail section.
Any ideas for how to solve this? The variant picture doesn't match there at all 😞
Hi,
Need to update the Liquid code to use the main product image as the default
Use javascript if required to handle dynamic image changes as per variant
Javascript code example
document.addEventListener('DOMContentLoaded', function () {
var variantSelect = document.querySelector('select[name="id"]'); // Adjust selector as needed
var imageContainer = document.querySelector('.product-image'); // Adjust selector as needed
variantSelect.addEventListener('change', function (event) {
var selectedVariant = event.target.value;
var selectedImage = document.querySelector('.variant-image[data-variant-id="' + selectedVariant + '"]');
if (selectedImage) {
imageContainer.src=selectedImage.src;
}
});
});
Please share your store URL as well
Evetually I found a solution here that worked for me:
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025