Hey everyone,
I need some help with an app i’m trying to install. The developer tells me i need to insert a custom id attribute to my product photo. I’ve already made a custom product template, however i’m not sure how and where to add this code. Would be great if someone can help me out! Here’s the code of my product.custom.liquid;
{% section 'product-template' %}
{% section 'product-recommendations' %}
{% section 'recently-viewed' %}
{% assign current_variant = product.selected_or_first_available_variant %}
Look in the ‘product-template.liquid’ section in the Sections folder and see if you can find where the product page photos are being output. It may be in a separate Snippet ({% include ‘product-gallery-or-whatever’ %}). Find the
tag and add an ID like this:
{% for media in product.media %}
<img id=“photo-{{ forloop.index }}” src=“{{ media | img_url: ‘600x600’ }}” alt=“{{ media.alt | escape }}”>
{% endfor %}
This will output IDs of ‘photo-1’,‘photo-2’, etc on each photo.
Hi Gina, thank you for your help.
The problem is that I only need a custom id attribute for a single product image, not for all. The app that i’m using lets customers upload their own photo and i would like the product photo to be updated to the uploaded photo of the customer on the product page. Hope you can help me out! Thanks in advance.
Kind regards,
Robert
Without knowing how your theme’s product page is set up, it’s hard to help. Can you just have the first image be the one updated? If that will work, just use the id ‘photo-1’ for your image app after adding the id as I instructed.
Hi Gina,
I think this is the piece of code you mean, however i’m not sure where to place the code you suggested.
{% if section.settings.media_layout contains 'thumbnails' and product.media.size > 1 %}
{% for media in product.media %}
{% render 'responsive-image', image: media.preview_image %}
Here’s the product page if that helps; https://premiumpaintings.nl/products/diamond-painting-eigen-foto?_pos=1&_psq=eigen&_ss=e&_v=1.0. The photo of the egg should be replaced with the image uploaded when clicking on “Kies een afbeelding”. Thanks again.
Robert