Shopify themes, liquid, logos, and UX
Hi,
I am using the Dawn theme for my store www.florabymillie.com. If you select a product that has variants, the image of the first variant displays as the main image in the product page. Can this be changed to have the main image on the collection page the same main image in the product page rather than a variant image ?
Any help would be great thanks.
Hi @Millie03
- As I understand, you don't want to change your product image when changing variants. If so, we're able to find a workaround.
- Please navigate to the Online store > Themes > Edit code. In the Section folder, open the main-product.liquid. There should be two codes like this one below in the file, find the first code.
{%- if product.selected_or_first_available_variant.featured_media != null -%}
{%- endif -%}
- Remove the code between the two lines above and add this code:
{%- assign featured_media = product.featured_media -%}
<li
id="Slide-{{ section.id }}-{{ featured_media.id }}"
class="feature--img product__media-item grid__item slider__slide is-active{% if single_media_visible %} product__media-item--single{% endif %}{% if featured_media.media_type != 'image' %} product__media-item--full{% endif %}{% if section.settings.hide_variants and variant_images contains featured_media.src %} product__media-item--variant{% endif %}"
data-media-id="{{ section.id }}-{{ featured_media.id }}"
>
{%- assign media_position = 1 -%}
{% render 'product-thumbnail', media: featured_media, media_count: media_count, position: media_position, desktop_layout: section.settings.gallery_layout, mobile_layout: section.settings.mobile_thumbnails, loop: section.settings.enable_video_looping, modal_id: section.id, xr_button: true, media_width: media_width, lazy_load: false %}
</li>
- Then add this code in the same file:
<script>
var swatches = document.querySelectorAll("[type='radio']");
var feature_img = document.querySelector(".feature--img");
swatches.forEach((swatch) => {
swatch.addEventListener('click', function(){
feature_img.style.display = "none";
console.log("swatches");
});
});
</script>
Please try and let me know if it works. If you don't want the code, you can revert the change in your theme here.
I hope that this can help you solve the issue.
If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here ☕.
B2B Solution & Custom Pricing | Product Labels by BSS
Need help from our expert? Kindly share your request with us via community@bsscommerce.com
Sorry, just to be clear - I would like the main product image to stay the same when you first go into the product page. At the moment it shows the first variant image. I only want the variant image to show when you click on the variant box.
also looking for a solution here... thanks
Following. Same for me. Picture that shows on Collection page for a product should remain as the main (first) picture when you click to go into the product on the product page.
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025