Show featured image until a variant is selected

Topic summary

A user seeks to display a product’s featured image by default, only switching to variant-specific images after a customer selects a variant option.

Current Issue:

  • The store (using PureTemplates v2.0.1) likely auto-switches images on page load instead of waiting for user interaction.

Proposed Solutions:

Multiple contributors suggest JavaScript-based approaches:

  1. Track the featured image using a data attribute and restore it when no variant image exists
  2. Locate variant change logic in main-product.liquid, product.liquid, or theme.js
  3. Add event listeners that only trigger image updates when users manually select variants
  4. Implement a flag (variantSelectedManually) to prevent automatic switching on initial page load

Key Technical Steps:

  • Find the variant change event handler (typically variant.addEventListener('change', ...))
  • Store the original featured image source
  • Update image only after user interaction, not on page load
  • Fall back to featured image if selected variant has no associated image

Current Status:
The original poster couldn’t locate the specific code mentioned and is awaiting personalized assistance via private message to implement the solution in their custom-designed store.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

Hi everyone
Does anyone know how to show featured image at first until a variant is selected?
Thanks in advance!!

https://a7■■■1-ra.myshopify.com/
Password: 1

Hey @Ryu888 ,

Yes, you can absolutely do that on Shopify — show the featured (default) product image until a variant is selected, after which the variant image appears. Here’s how you can implement it, depending on your theme and setup.

JavaScript-based (Theme-agnostic):

This is a general solution that works in most Shopify themes:

  1. In your product.liquid or main-product.liquid file (or wherever the product form and images are rendered), add a data attribute to track the featured image:

  1. Add JS to handle variant changes:

Note: Adjust selectors based on your theme. Some use data-product-id, or dynamic section IDs like ProductJson-{{ section.id }}.

Would you like help with this specific to your theme (e.g., Dawn, Broadcast, Debutify, etc.)? I can tailor the solution accordingly. Let me know which theme you’re using!

Best,

Rajat

Shopify Expert

Thank you for your help Rajat

I’m currently using PureTemplates ver 2.0.1
It would be much help if you could guide me to fix this
TIA

Hey @Ryu888 ,

Could you please share the correct store password? Because i check and found that it’s not correct. Correct password will help me to take a look in your store to provide you better solution as I can.

In the previous days I do same task for one of my Customer and I would like to tell you how you can implement the same thing in your store.

Here are the steps you can follow.

  1. Go to product page template: First you need to go in the product page template. You can find product page template by these steps: Go to Shopify Admin > Online Store > Edit Code. In the Edit code search bar you have to search for main-product.liquid or product.liquid.
  2. Find the variant image Switching logic: Usually you will find the JavaScript Block like this:
variant.addEventListener('change', function(){
     // code that updates image 
});

If you don’t find it from the main-product.liquid then you can search it from theme.js file.

  • After founding it now you have to update the JS with this one code:
document.addEventListener("DOMContentLoaded", function() {
  const featuredImage = document.querySelector('.product__media img').src;
  const variantSelect = document.querySelector('[name="id"]');

  variantSelect.addEventListener('change', function() {
    const selectedOption = this.options[this.selectedIndex];
    const imageId = selectedOption.getAttribute('data-image-id');

    if (imageId) {
      // Replace with your logic to switch to variant image
      const variantImage = document.querySelector(`img[data-image-id="${imageId}"]`);
      if (variantImage) {
        document.querySelector('.product__media img').src=variantImage.src;
      }
    } else {
      // No variant image, fallback to featured
      document.querySelector('.product__media img').src=featuredImage;
    }
  });
});

Now you have to test on the product page which has variants.

Thanks

1 Like

Thank you for your help thescriptflow
Password : 123456

I will try this steps and where I should put code after I found that code?

I gave you detailed guide you can read my reply again.

I mention two theme files.

  1. main-product.liquid or product.liquid.
  2. theme.js

Please try to paste the code and let me know if this is work for you. Otherwise I provide you another code that works.

Thanks

Couldn’t find this code sir

variant.addEventListener(‘change’, function(){
// code that updates image
});

May I know where you check this coding?

Or would you like to share the collab code in the p/m so that I personally take a look and add the featured image as a first image.

I checked main-product.liquid or product.liquid.

Since I asked some designer to make my shop so I dont really know the code setting

I just send you a p/m. Waiting for your reply.

Hi @Ryu888 ,

Yes, you can definitely show the featured image first and only change it when a variant is selected. By default, Shopify themes often auto-switch to the first variant image, but you can customize this behavior.

Here’s how you can do it:

Solution (using JavaScript):

You’ll need to modify your product page JavaScript to prevent the image from switching automatically when the page loads.

1. Locate your product page JavaScript file, often found in:

  • Assets/product.js or similar

  • Or sometimes directly within your theme files (like product-template.liquid or main-product.liquid)

2. Prevent automatic variant image switching on load: Find the code that changes the main image when a variant is selected. It’ll look something like this:

js

if (variant && variant.featured_image) {
updateProductImage(variant.featured_image);
}

Modify it so it only triggers when the user selects a variant manually, not on initial page load. For example:

let variantSelectedManually = false;

document.querySelectorAll(‘input[name=“id”], select[name=“id”]’).forEach(input => {
input.addEventListener(‘change’, () => {
variantSelectedManually = true;
const selectedVariant = getSelectedVariant(); // use your theme’s variant selector logic
if (selectedVariant && selectedVariant.featured_image) {
updateProductImage(selectedVariant.featured_image);
}
});
});

// Prevent auto-switching on initial load
if (!variantSelectedManually) {
// Do not update the image
}

3. Or an easier approach (if using Dawn theme or similar): You can remove or comment out the media_gallery.update() call that happens on variant change inside product-form.js.

Let me know your theme name and I’d be happy to give more theme-specific help if needed!

Hope this helps :blush:

1 Like