Issue with hreflang tags

Hi,

I’m experiencing an issue with the hreflang tags on my Shopify store.
All the tags are incorrectly associated with Sweden (SE) regardless of the actual language and country target.

I need to adjust these tags so each language version of my site is correctly associated with its respective country code. Can anyone guide me on how to correctly edit these tags in the theme.liquid file or suggest an alternative solution?

Thank you!

Hi @Daxegren

Welcome to Shopify Community.

Can you share your store URL (with password if there is any).

It will help the me as well as community members to better understand and suggest you the solution.

Thanks,

Sajat

Hi,

It looks like this:

Hi @Daxegren

Thank you for the additional information.

To have your own hreflang tags, you need to do two things;

  • Disable the auto generated hreflang tags
  • On theme.liquid, after {% render ‘meta-tags’ %}, please put the following code
{% assign lines = content_for_header | newline_to_br | split: '
' %}
    {% for line in lines %}
      {% if line contains '

- Now, one the same file, after <link rel="canonical" href="{{ canonical_url }}">, please put the following code

```markup

    {% if template == 'index' %}
      
      
      
      
      
    {% endif %}
    
    {% if template == 'collection' %}
      
      
      
      
      
    {% endif %}
    
    {% if template == 'product' %}
      
      
      
      
      
    {% endif %}
    
    {% if template == 'page' %}
      
      
      
      
      
    {% endif %}
    
    {% if template == 'article' %}
      
      
      
      
      
    {% endif %}
  • IMPORTANT - DO NOT FORGET to change the URL, hreflang values to you own domain and values. This will change the hreflang tag values for Home Page, Collection Page, Product Page, Custom Page and Blog Post.
  • If you add new language, you need to the hreflang tag for that language.

Thank you.

Sajat

P.S. If I find any easier solution than this, I will surely update you on this thread.


If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.

Thank you for quick respond. I’m about to try it out.

Why do you write some country codes double nl-nl and de-de and then some single like en and fr?:

Hi @Daxegren

I wanted to show that both language and location can be added on the hreflang tag and acts as an signal for the search engines regarding language and location.

For e.g. only ‘en’ suggests that the language is on English whereas ‘en-gb’ suggest language is on English and location is specified as UK

If you specify ‘en-au’, then the language is English but the targeted country is Australia.

So, it depends upon the language and the country you are targeting.

You can just use the language or combine them with location on hreflang tags. This helps in directing users to relevant regional or language specific site versions.

Thank you,

Sajat