Parsing shop.name to json when it includes an & (ampersand)

Parsing shop.name to json when it includes an & (ampersand)

david_thehub
Shopify Partner
2 0 1

Good night,

 

How should I parse to json a shop.name including an "&"? Right now, for a store titled  "Test & Store", the code {{ shop.name | json }} returns something like "Test \u0026amp; Store".

 

This is causing problems with Google indexation.

 

One solution would be using "and" instead of "&", but I am afraid it could cause SEO problems. Another solution, is using the store name hardcoded instead of the code "shop.name | json", but if in the future there is change in the shop name, it will need to be searched and updated.

 

Any advice?

 

Thanks in advance,

Reply 1 (1)

Wayne_Foster
Shopify Partner
15 0 2

For anyone else that lands here - I came across the same issue when parsing products titles for inclusion in a dataLayer for GTM.  Got around it by replacing the parsed ampersand with just the html code;

 

{{ line_item.product.title | json | replace: "\u0026amp;", "\u0026" }}

So in your instance, maybe try:

 

{{ shop.name | json | replace: "\u0026amp;", "\u0026" }}