Why is my new product badge code displaying in two different places?

Topic summary

A user implemented custom product badge code using metafields in their price.liquid file, but the badge unexpectedly appeared in two locations: correctly next to built-in badges on product pages, but also unwrapped next to prices on collection grid pages.

Solution provided:

  • Wrap the badge code with a conditional template check: {%- if template.name contains 'product' -%}
  • This restricts the badge display to product pages only
  • Prevents the badge from rendering on collection pages

Outcome:

  • The solution successfully resolved the issue
  • The badge now displays inline with built-in SALE/SOLD OUT badges only on product pages as intended
Summarized with AI on November 12. AI used: claude-sonnet-4-5-20250929.

Hi everyone,

I’ve just implemented a code into price.liquid to display product badges using metafields, however it is showing up on both product page AND collection grid.

Initially I put this code into price.liquid, in the hopes that the new badge would show up next to the built-in SALE and SOLD OUT badges. It is showing up perfectly next to the built-in badges in product pages but it also shows up in the collection grid next to the price, as a badge.

I have tried putting the code into main-product.liquid but this makes it only shows up ABOVE the built in badges, not inline and next to the built in badges like I want it to.

What am I be doing wrong?

This is the code I have used in both price.liquid and main-product.liquid

{% comment %}ADD NEW METAFIELD{% endcomment %}
{% assign product_badge_best_seller = card_product.metafields.custom.product_badge_best_seller %}
{% if product.metafields.custom.product_badge_best_seller != blank %}

{{ product.metafields.custom.product_badge_best_seller | metafield_tag }}

{% endif %}

Hi @shinramen

Please wrap your code into this to make it work for the product page only.

{%- if template.name contains 'product' -%}
{% comment %}ADD NEW METAFIELD{% endcomment %}
{% assign product_badge_best_seller = card_product.metafields.custom.product_badge_best_seller %}
{% if product.metafields.custom.product_badge_best_seller != blank %}

{{ product.metafields.custom.product_badge_best_seller | metafield_tag }}

{% endif %}
{%- endif -%}

Hi Dan-From-Ryviu,

Thank you so much!! The code works like a charm :slightly_smiling_face:

1 Like

Happy I could help :grin: