Skip to content

Instantly share code, notes, and snippets.

@joe-dempsey
Created January 16, 2017 17:01
Show Gist options
  • Save joe-dempsey/d4326d7a08790129bcc07a7c08667662 to your computer and use it in GitHub Desktop.
Save joe-dempsey/d4326d7a08790129bcc07a7c08667662 to your computer and use it in GitHub Desktop.
dynamic href lang tags liquid shopify
{% comment %}
Here we have 2 stores:
www.urbanexcess.com
www.usd.urbanexcess.com
set dynamic href lang tags for each to avoid dup. content issues
{% endcomment %}
<!-- hreflang tags ================================================== -->
<link rel="alternate" hreflang="x-default" href="{{ canonical_url | replace: shop.domain, 'www.urbanexcess.com' }}" />
<link rel="alternate" href="{{ canonical_url | replace: shop.domain, 'www.urbanexcess.com' }}" hreflang="en-GB" />
<link rel="alternate" href="{{ canonical_url | replace: shop.domain, 'www.usd.urbanexcess.com' }}" hreflang="en-US" />
<link rel="alternate" href="{{ canonical_url | replace: shop.domain, 'www.urbanexcess.com' }}" hreflang="en" />
@Keschm
Copy link

Keschm commented Oct 17, 2022

This doesn't work when you use subfolders, like /en for example.

@joe-dempsey
Copy link
Author

of course - if you're using subfolders you need to manage hreflang tags using code that caters for that
usually shopify's native hreflang tags cater for this (as mapped to markets)
the above is for cases where they don't and you use seperate sites and need to get the automated ones removed.

@Keschm
Copy link

Keschm commented Mar 2, 2023

Hi Joe, thank you for your comment. I found a solution how to get it working with subfolders.
You can take a look at it at this website
I think this website is the only one where it is working correctly when you work with Shopify Markets.
The automated tags which Shopify uses I switched off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment