June 12, 2024

Adding Product Image Sliders in Shopify

Arrow pointing left
back to blog

about

An optimized product page experience starts with displaying high quality product images in a compelling way.

the author

Ryan Shaw
Director of Growth

share this post

Interested in adding a product image slider to your Shopify store?

Whether you decide to use a third party solution or make the edits to your theme natively, we’ll walk you through every step involved in this process.

Optimize your product page experienceWith Shogun’s user-friendly visual editor, anyone can create highly customized, feature-rich product pages on Shopify.Get started now

What Are Sliders Used for in Shopify?

Sliders are slideshows featured as part of a web page. They can be automated (slides transition from one to the next on their own) or manual (the visitor must click on an arrow or similar design element to switch to the next slide). 

The main benefit of sliders is that they allow you to add more content to the page without making it longer or more cluttered. 

There are many ways that you can utilize sliders on your Shopify store, such as:

  • Customer testimonials: Allow customers to scroll though some of the most glowing reviews and persuasive quotes regarding the product you’re promoting. 
  • Company logos: You can add a slider of company logos to add social proof to a page — for example, B2C brands could add the logos of any recognizable news outlets that have given their product a positive review, and B2B brands could show off some of their biggest clients. 
  • Promotional offers: Many Shopify merchants will use a banner at the top of the page to highlight a promotional offer, such as a holiday sale or free shipping. If you have multiple offers that you would like to display, sliders provide you with an efficient way to do so. 

Sliders are also a particularly useful tool for presenting product images. 

The key disadvantage to online shopping is that customers don’t get a chance to evaluate products in-person before they commit to making a purchase. So, you’ll need to provide as much information as you can through your website in order to convince them to hit the buy button — and visual information is much more compelling than any other type of content. 

Indeed, a 2018 survey found that 60% of consumers feel like they need to see three or four images of a product before they feel comfortable purchasing it online. An additional 13% need to see five or more images. 

With sliders, you can add the number of images your customers expect while still maintaining a sleek, modern page design. In this instance, you can have your cake and eat it, too.

Using Custom Code to Add a Product Image Slider in Shopify

Unfortunately, many Shopify themes don’t have a built-in product image slider feature. 

In that case, you could still add a product image slider by editing your theme code. The following code example demonstrates how this is done:

Step 1. Log in to your Shopify account and select the sales channel you would like to edit. 

Log in to your Shopify account and select the sales channel you would like to edit. 

Step 2. Open the “…” menu located next to your theme and select “Edit code”.

Open the “...” menu located next to your theme and select “Edit code”.

Step 3. Open the “Snippet” folder in the left sidebar and select “Add a new snippet”.

Select “Add a new snippet”.

Step 4. Name the file “custom-product-slider”, then select “Done”. 

Select “Done”. 

Step 5. Add the following code to your new snippet:

{% if product.images != null %}
  <div class="carousel product__image-slider" role="document" aria-label="{{ 'products.modal.label' | t }}" tabindex="0">
    {%- for media in product.media -%}
      <div class="carousel-cell">
        {% if media.media_type == "video" %}
          {{ media | media_tag: image_size: "720x", autoplay: true, loop: loop, controls: true, preload: "none", autoplay: true, height: "100%", width: "100%" }}
        {% else %}
          <img src="{{ media | img_url: '1440x' }} 1440w, {{ media | img_url: '1080x' }} 1080w, {{ media | img_url: '720x' }} 767w, {{ media | img_url: '480x' }} 480w" data-flickity-lazyload-srcset="{{ media | img_url: '1440x' }} 1440w, {{ media | img_url: '1080x' }} 1080w, {{ media | img_url: '720x' }} 767w, {{ media | img_url: '480x' }} 480w" sizes="(min-width: 480px) 1440px, 1080px, 767px, 480px" data-flickity-lazyload-src="{{ media | img_url: 'master' }}" alt="{{ media.alt | escape }}" border="0" data-media-id="{{ media.id }}" />
        {% endif %}
      </div>
    {%- endfor -%}
  </div>
  
  {% if product.images.size > 1 %}
    <div class="carousel product__image-thumbnail">
      {%- for media in product.media -%}
        <div class="carousel-cell">
          <img src="{{ media | img_url: '1440x' }} 1440w,
            {{ media | img_url: '1080x' }} 1080w,
            {{ media | img_url: '720x' }} 767w,
            {{ media | img_url: '480x' }} 480w"
            data-flickity-lazyload-srcset="
              {{ media | img_url: '1440x' }} 1440w,
              {{ media | img_url: '1080x' }} 1080w,
              {{ media | img_url: '720x' }} 767w,
              {{ media | img_url: '480x' }} 480w"
            sizes="(min-width: 480px) 1440px, 1080px, 767px, 480px"
            data-flickity-lazyload-src="{{ media | img_url: 'master' }}"
            alt="{{ media.alt | escape }}"
            border="0"
            data-media-id="{{ media_id }}" 
          />
        </div>
      {%- endfor -%}
  </div>
  {% endif %}
{% else %}
  {{ 'product-1' | placeholder_svg_tag }}
{% endif %}

<script>
var elem = document.querySelector('.carousel.product__image-slider');
var flkty = new Flickity( elem, {
contain: true,
imagesLoaded: true,
lazyLoad: 1,
wrapAround: true,
pageDots: false,
{% if product.images.size < 2 %}
prevNextButtons: false,
{% endif %}
adaptiveHeight: true
});
var elemThumbnail = document.querySelector('.carousel.product__image-thumbnail');
var flktyB = new Flickity( elemThumbnail, {
asNavFor: '.carousel.product__image-slider',
contain: true,
imagesLoaded: true,
lazyLoad: 4,
pageDots: false,
prevNextButtons: false
});
</script>

Save your changes. 

Save your changes. 

Step 6. Open the “Sections” folder and select the “main-product.liquid” file.

Select the “main-product.liquid” file.

Step 7. To replace the standard featured image section with a product image slider, search for the following code:

{% render 'product-media-gallery', variant_images: variant_images %}

And replace it with this code:

      {% comment %}{% render 'product-media-gallery', variant_images: variant_images %} {% endcomment %}
      {% render 'custom-product-slider' %}

Finally, save your changes. 

Save your changes. 

Once you’ve completed these steps, you’ll find that your product pages with multiple product images now have a product image slider. 

Your product pages with multiple product images will now have a product image slider.

Using Shogun to Add Product Image Sliders in Shopify

It should be noted that the code example detailed above was demonstrated on the latest version of Dawn, Shopify’s default theme. That code may not work if you use another theme or an earlier version of Dawn.

Also, even if that code does work for you, customizing the styling of this slider would require editing the code — and if you don’t have extensive web development experience, that could be a quite difficult and time-consuming process.

Shogun provides a much easier way to add and edit product image sliders for your Shopify store:

Step 1. Open the Shogun app and select the page you would like to edit. 

Open the Shogun app and select the page you would like to edit. 

Step 2. This will open the page in Shogun’s visual editor, which provides you with a vast library of elements that you can use to customize your pages. Select the “Elements” icon (the one that looks like a plus sign inside a circle) in the left sidebar to open the elements library. 

Open the elements library. 

Step 3. Click and hold on the “Slider” element icon, then drag it to wherever you want to place the slider on your page. 

Click and hold on the “Slider” element icon, then drag it to wherever you want to place the slider on your page. 

You’ll find that Shogun offers a wide variety of options for customizing your product image slider, including:

  • Select an animation for when one slide switches to the next, such as fade in, zoom in, slide right, or slide down
  • Choose whether arrows are displayed (you can customize the color of these arrows as well)
  • Determine whether the slider is automated or manual
There are many options available for customizing your Shopify sliders in Shogun.

As you can see, Shogun gives you complete control over your product image sliders.

Create optimized product pages with ShogunShogun enables growing brands to create customized, feature-rich product page experiences for their Shopify store.Get started now

You might also enjoy

Get started for free

Get hands on with everything you need to grow your business with a comprehensive suite of tools.
Start now
Arrow pointing up and to the right Arrow pointing up and to the right