Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
},
The error is only appearing on my Collections pages. Here is the JSON snippet from Shopify:
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "ItemList", "itemListElement": [ {%- for product in collection.products -%} {% if product.type=='giftbox_ghost_product' %}{%continue%}{%endif%} { "@type": "ListItem", "position": {{ forloop.index | json }}, "url": {{ product.url | json }}, "name": {{ product.title | json }} } {% unless forloop.last %},{% endunless %} {%- endfor -%} ] } </script>
An example page that has this error is: https://www.wishgardenherbs.com/collections/respiratory-wellness
I cannot figure out the error. Does anyone have a guess?
Thank you,
Bill
Solved! Go to the solution
This is an accepted solution.
Based on the code provided, you have an if statement inside the forloop. You add comma when its the last forloop, but since you have if statement which takes a filter and only continue if it meets the certain condition. So, it never meets the forloop.last.
Try the edited code below instead:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ItemList",
"itemListElement": [
{%- for product in collection.products -%}
{% if product.type=='giftbox_ghost_product' %}
{
"@type": "ListItem",
"position": {{ forloop.index | json }},
"url": {{ product.url | json }},
"name": {{ product.title | json }}
}
{% unless forloop.last %},{% endunless %}
{% endif %}
{%- endfor -%}
]
}
</script>
Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
This is an accepted solution.
Based on the code provided, you have an if statement inside the forloop. You add comma when its the last forloop, but since you have if statement which takes a filter and only continue if it meets the certain condition. So, it never meets the forloop.last.
Try the edited code below instead:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ItemList",
"itemListElement": [
{%- for product in collection.products -%}
{% if product.type=='giftbox_ghost_product' %}
{
"@type": "ListItem",
"position": {{ forloop.index | json }},
"url": {{ product.url | json }},
"name": {{ product.title | json }}
}
{% unless forloop.last %},{% endunless %}
{% endif %}
{%- endfor -%}
]
}
</script>
Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
Thank you so much! I replaced the code with your code and submitted the fix to Google and it appears to have worked! Thanks again! I love this Community!
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024