Eliminate image of variant's dimensions from the slider on Shopify

I am facing an issue with our Shopify store where duplicate variant images for colors are being displayed on the storefront. Although everything looks fine in the dashboard, the duplication is causing confusion for customers. Shopify support has advised manually removing the duplicate images, but this is a daunting task due to the large number of variants we have.

Is there a way to fix this via code rather than manual deletion? Can I hide or remove the duplicated images using Liquid code in Shopify or through JS/CSS?

Below is the code that is responsible for generating the product images:

{% assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image %}
<div class="flexslider product_gallery product-{{ product.id }}-gallery {% if product-images == blank %}product_slider{% endif %} {% if settings.product_thumbs == false %}animated fadeInUp{% endif %}">
  <ul class="slides">
    {% for image in product.images %}
      <li data-thumb="{{ image | product_img_url: '1024x1024' }}" data-title="{% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}{{ product.title }}{% else %}{{ image.alt | escape }}{% endif %}">
        {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}
          {% assign src = image.alt | split: 'src="' %}
          {% assign src = src[1] | split: '"' | first %}

          {% if src contains '?' %}
            {% assign src = src | append: '&amp;autoplay=1' %}
          {% else %}
            {% assign src = src | append: '?autoplay=1' %}
          {% endif %}

          <div class="video-container {% if image.alt contains 'vimeo' %}vimeo{% else %}youtube{% endif %}">
            <div>
              <a href="{{ src }}" class="fancybox fancybox.iframe" data-fancybox-group="{{ product.id }}" title="{{ product.title | escape }}">
                {{ image.alt }}
              </a>
            </div>
          </div>
        {% else %}
          <a href="{{ image | product_img_url: 'master' }}" class="fancybox" data-fancybox-group="{{ product.id }}" title="{{ image.alt | escape }}">
            <img  src="{{ image | product_img_url: '1024x1024' }}"
                  alt="{{ image.alt | escape }}"
                  class="lazyload transition-in cloudzoom {% if featured_image.id == image.id %}featured_image{% endif %}"
                  data-image-id="{{ image.id }}"
                  data-index="{{ forloop.index0 }}"
                  data-cloudzoom="zoomImage: '{{ image | product_img_url: 'master' }}', tintColor: '{{ settings.shop_bg_color }}', zoomPosition: 'inside', zoomOffsetX: 0, touchStartDelay: 250"
                   />
          </a>
        {% endif %}
      </li>
    {% endfor %}
  </ul>
</div>

Answer №1

If you want to determine the number of color options available in your product, try incorporating the following code snippet:

 {% for option in product.options_with_values %}
    {% if option.name == "Color" %}
        {% capture colorCount %}
          {{ option.values.size }}
        {% endcapture %}
    {% endif %}
 {% endfor %}

You can then use this color count to limit the display of images based on the number of colors available. Simply add limit: colorCount to the loop that iterates over product images:

{% for image in product.images limit:colorCount %}

It's possible that the excessive images appearing could be related to a data issue during csv uploading. Implementing this solution might help control the image display problem.

I hope this suggestion guides you towards resolving the issue effectively.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the array being reset for no apparent cause?

Can you review this code for me? I am confused as to why it is showing [] at the last line. const arrcodces =[1,2,3,4] const arrOfPWs=[] const data=[] const arrOfPWs_2=[] const base=[ '2','3','4','5','6',&a ...

What could be causing the issue with the navigation circles on my carousel not updating when clicked?

I created my own carousel from scratch and it's working perfectly fine except for one issue - clicking on the navigation circles. When using the interval/infinite loop prop, the circles update to the correct active slide as expected. The same goes fo ...

I would greatly appreciate any recommendations on how to troubleshoot and

I've been working on the "Map the Debris" challenge at freecodecamp, and I'm facing an issue. While my code works fine in my PC's editor, it doesn't satisfy the conditions when I paste it into the website area. Any suggestions on how t ...

How to customize the style of a td element in an HTML table

Attempting to modify the style of a td element: .valuator .sw-slots table, tr, td { width 100% } Even after trying to override with this code: td.license-name-td{ width: 100px !important; } The global style always takes precedence over my specific s ...

Is there a convenient method to combine arrays of objects in JavaScript using ellipses or an equivalent approach?

let array = [ {id: 1, data: {foo: "bar 1"}}, {id: 2, data: {foo: "bar 2"}} ]; //If ID doesn't exist, add new element to the array array = [...array, {id: 3, data: {foo: "bar 3"}}] console.log(array); //If ID exists, replace data object with new ...

Issue with Node.js express-session not retrieving myvar value (or generating a different sessionID)

After experimenting with express-session, I encountered an issue where I couldn't access any of my previously stored variables in the session. Additionally, I noticed that the session ID had changed. Can anyone explain why this is happening? This is ...

What are some of the techniques for customizing the DOM generated by material-ui in ReactJS?

Is there a way to style the dynamically created DOM elements from material-ui? I'm currently using GridListTileBar, which generates a DOM structure like this for its title property. <div class="MuiGridListTileBar-title-29" data-reactid=".0.3.0.$3 ...

Stop jQuery from resetting the background image when using fadeOut()

Currently, I am using fadeIn and fadeOut functions with jQuery to create a fading effect. However, when the final fade out occurs, the entire CSS table fades out and the background image of the CSS body comes into view. Despite setting the background-posit ...

Alert classes are not included in bootstrap 5 npm package

In my Angular 13 project, I am utilizing Bootstrap version 5.2.1. While most components are working as expected, the alert component seems to be missing some styling elements. Specifically, I have noticed that alerts with the classes alert-success and aler ...

Labels are overlapping each other and being aligned to the right side

Working with the most up-to-date version of Bootstrap, I am currently designing a search bar featuring a dropdown menu preceding the search button. Upon clicking the dropdown, various controls are revealed. Below is the HTML code for this configuration: ...

Setting up Vue CLI 4 with ESLint, TypeScript, Stylelint for SCSS, and Airbnb rules in the VS Code editor with automatic fixes on save

After struggling with configuring Vue CLI 4 with ESLint, Prettier, Airbnb rules, TypeScript, and Vetur, I found myself at a crossroads. The challenges continued to mount as the nature of the problem evolved from my previous attempts.: How to configure Vue ...

In React Native, the onPress handler will continue to be triggered indefinitely after 2-3 presses

import firebase from './Firebase'; import { useState, useEffect } from 'react'; import { StyleSheet, Text, View, Button, FlatList } from 'react-native'; import { TextInput } from 'react-native-web'; import { setStatu ...

What is the best way to adjust the size of carousel images within a box element?

How can I ensure that carousel pictures are displayed clearly within the box without overflowing? The code I tried resulted in the pictures overflowing from the box and not being visible clearly. How can I resolve this issue? .container { width: 1490px; ...

`JQuery fadeOut seems to have a limitation where it only applies to the

I have a group of divs, each containing an anchor tag that triggers a JavaScript function (which uses AJAX to delete a row from a table). Here's an example setup: <div id="container"> <div><a id="btn" onclick="deleteRow()">Delet ...

What are the steps to get this HTML form functioning properly?

I am currently working on a website template that includes a contact form in HTML. Unfortunately, I am facing difficulties in configuring it to send the form contents via email. Despite my attempts at creating a PHP script for this purpose, I have been uns ...

When multiple input fields with an iterative design are using the same onChange() function, the specific event.target.values for each input

I'm in the process of developing a dynamic select button that adjusts based on the information entered into the iterative input fields I've set up. These input fields all utilize the same onChange() function. for (let i = 0; i < selectCount; i ...

Displaying incorrect symbols with icon fonts

I have successfully integrated icon fonts into my simple web page. Check it out on jsFiddle here My design is similar to this example, but instead of bars, I see a snake icon displayed. How can I fix this issue with the fonts? Here is the code snippet: ...

Building paths through a jQuery loop

Transform String into Delimited Array, Generate Loop of Check Boxes, and Build New String Given String = "Folder Tier1\Folder Tier2\Folder Tier3\Folder Tier4\Folder Tier5\Folder Tier6\" (Missing) Use "\" as a delimi ...

Display a dialogue box when encountering a Vuetify error. Only open the dialogue box under certain conditions

I am currently implementing vuetify into my project. The main issue I am facing is related to the dialog component, which I only want to open in case of an error. The scenario involves a button calling a backend service to save a product in the database, a ...

The issue persists with the customized Bootstrap carousel featuring thumbnails

By combining http://codepen.io/srkimir/pen/mGbrf and http://codepen.io/transportedman/pen/NPWRGq , I successfully created a fading carousel with thumbnails similar to the one in http://codepen.io/kikibres/pen/gpZoXz . However, when trying to implement ...