johnhgaspay
johnhgaspay

Reputation: 51

Is there a way to implement hreflang on subfolder in Shopify

Here my current custom code in shopify. 

<link rel="alternate" hreflang="en-au" href="{{ canonical_url | replace: 'us', 'au' }}"  />

the output goes like this via source code

<link rel="alternate" hreflang="en-au" href="/en-au/pages/faqs"  />

The problem with the code above is that when visitors view it in other country like UK it won't /en-uk in the URL. I am trying to get to make it more dynamic after /en- so that I can implement on other countries. Here is the code I've tried but it gets error showing "liquid error" in Shopify

<link rel="alternate" hreflang="en-au" href="{{ canonical_url | replace: '{{ localization.country.iso_code }}', 'au' }}"  />

Upvotes: 0

Views: 247

Answers (1)

Rado
Rado

Reputation: 739

If you think that your last part will work, you simply have to extract the second liquid code in a variable and use it. Here is what I mean:

Instead of

<link rel="alternate" hreflang="en-au" href="{{ canonical_url | replace: '{{ localization.country.iso_code }}', 'au' }}"  />

do like

{% assign iso_code = localization.country.iso_code %}
<link rel="alternate" hreflang="en-au" href="{{ canonical_url | replace: iso_code, 'au' }}"  />

Upvotes: 0

Related Questions