Oudated & Unnecessary Meta Tag Escaping

Context

Many themes still contain the outdated og:price:amount
& og:price:currcency product meta property tags.

Example Old

<meta 
    property="og:price:amount" 
    content="{{ product.price | money_without_currency | strip_html | escape }}"
>

<meta 
    property="og:price:currency" 
    content="{{ cart.currency.iso_code }}"
>

Example New

<meta
    property = 'product:price:amount'
    content = '{{- product.selected_or_first_available_variant.price | money_without_currency -}}'
/>

<meta
    property = 'product:price:currency'
    content = '{{- shop.currency -}}'
/>

As can be seen in the old example above they usually also contain
the incorrect product.price reference instead of variant.price.

Question

I couldn’t find why or where from the price escaping code came from.

The money_without_currency filter returns a clean decimal value
( XX.XX ) for the price no matter the store’s currency formatting rules.

Why then did they try to strip_html & escape the contents?

Is it just a legacy artifact?

The only thing that money_without_currency doesn’t account for are:

  • Prices from countries where the decimal point is a comma XX,XX / X.XXX,XX
  • Prices larger than 1000XX,XXX.XX

While the resulting formats might technically work , they should be normalized.
XXXX.XX

Hey - thanks for highlighting this. I notice Dawn follows the patterns you described above: dawn/snippets/meta-tags.liquid at d2612f03103a114c965be5291032c847c968350c · Shopify/dawn · GitHub

Have connected with the team who owns this to determine why.

1 Like

Thanks , related to that I had found an unaddressed issue from 2021.

1 Like

The price needs to have escape. Money without currency returns HTML; since admin for currency formatting will let you wrap the Liquid output of product.price in HTML tags. This is a very old feature of Shopify, and when currency switching was introduced to the platform, the HTML output was dropped from anything that isn’t the shop.currecy.

The currency format should be cart.currency. That will match the currency used for a selected market / market in the URL route. If shop.currency is used, then it will always show the store’s default currency - which may not match what the actual price is based on.

Having the price as product.selected_or_first_available_variant would be a good change. The page_image object reflects the selected or available variant, so there’s no risk of a mismatch between the image and the price.

Thanks for the link on the open graph price format that shows there should be no separators (aside from decimals). Unfortunately there’s no currency formatting option currently to remove the commas. I couldn’t think of a workaround since {{ price | money_without_currency | replace: ',' , '' }} may not work since Liquid doesn’t know which currency format the store is using. I can raise this internally.