Hreflang Attributes Not Showing

Hi everyone,

I’m encountering a strange issue that even Shopify support hasn’t been able to resolve, so I’m hoping someone here might have some insight.

Our client operates multiple stores with various markets and languages (NA, EU, UK, and MX, each with multiple markets and languages). They’re working with an SEO agency to implement the correct hreflang attributes for each store. Our task was to compile these attributes and render them dynamically in the head—fairly straightforward.

To avoid conflicts, I asked Shopify to disable their auto-generated hreflang attributes, which they did. We then implemented custom logic in a snippet to compile and render the correct attributes dynamically in the theme’s head.

Here’s the issue: while the snippet appears to work, it only renders the x-default attribute and none of the others. Oddly, the space for the missing attributes is still being allocated in the head (see the screenshot I’ve provided). Shopify suggested it might be caused by an app, but I’ve disabled all app embeds, and the issue persists.

The code is currently in an unpublished “Testing” theme, but I also tried deploying it to the live theme to rule out any theme-specific quirks—same result.

I’m wondering if this is just a simple oversight on my part. I expected Shopify to point out an obvious fix, but even their team seems stumped at the moment.

Has anyone else experienced something similar? Any guidance or suggestions would be greatly appreciated.

Thanks in advance!

C


1 Like

@cory_kelley could you please share the snippet used to render the hreflang attributes?

@daniel we tried doing this dynamically at first, a few different ways, but at this point we’re just outputting exactly what the SEO agency our client works with gave us based on the page the user is viewing. Again, the space is allocated in source, so I feel like the snippet is trying to render something…

{% if template == 'index' %}
  {% comment %} X-Default {% endcomment %}
  <link
    rel="alternate"
    hreflang="x-default"
    href="https://www.singer.com" />

    {% comment %} North America {% endcomment %}
  <link
    rel="alternate"
    hreflang="fr-ca"
    href="https://www.singer.com/fr-ca" />
  <link
    rel="alternate"
    hreflang="en-us"
    href="https://www.singer.com" />
  <link
    rel="alternate"
    hreflang="en-ca"
    href="https://www.singer.com/en-ca" />
  <link
    rel="alternate"
    hreflang="es-us"
    href="https://www.singer.com/es" />
  <link
    rel="alternate"
    hreflang="es"
    href="https://www.singer.com/es" />

    {% comment %} Mexico {% endcomment %}
  <link
    rel="alternate"
    hreflang="es-MX"
    href="https://mexico.singer.com/es" />
  <link
    rel="alternate"
    hreflang="en-MX"
    href="https://mexico.singer.com" />

    {% comment %} UK {% endcomment %}
  <link
    rel="alternate"
    hreflang="en-gb"
    href="https://uk.singer.com" />

    {% comment %} Europe {% endcomment %}
  <link
    rel="alternate"
    hreflang="de-at"
    href="https://europe.singer.com/de-at" />
  <link
    rel="alternate"
    hreflang="cs-cz"
    href="https://europe.singer.com/cs-cz" />
  <link
    rel="alternate"
    hreflang="da-dk"
    href="https://europe.singer.com/da-dk" />
  <link
    rel="alternate"
    hreflang="fi-fi"
    href="https://europe.singer.com/fi-fi" />
  <link
    rel="alternate"
    hreflang="de"
    href="https://europe.singer.com/de" />
  <link
    rel="alternate"
    hreflang="en-de"
    href="https://europe.singer.com" />
  <link
    rel="alternate"
    hreflang="it-it"
    href="https://europe.singer.com/it-it" />
  <link
    rel="alternate"
    hreflang="no-no"
    href="https://europe.singer.com/no-no" />
  <link
    rel="alternate"
    hreflang="es-es"
    href="https://europe.singer.com/es-es" />
  <link
    rel="alternate"
    hreflang="sv-se"
    href="https://europe.singer.com/sv-se" />
  <link
    rel="alternate"
    hreflang="de-ch"
    href="https://europe.singer.com/de-ch" />
  <link
    rel="alternate"
    hreflang="en-eu"
    href="https://europe.singer.com" />

{% elsif page.handle == 'pfaff' %}
  {% comment %} X-Default {% endcomment %}
  <link
    rel="alternate"
    hreflang="x-default"
    href="https://www.singer.com/pages/pfaff" />

    {% comment %} North America {% endcomment %}
  <link
    rel="alternate"
    hreflang="fr-ca"
    href="https://www.singer.com/fr-ca/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="en-us"
    href="https://www.singer.com/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="en-ca"
    href="https://www.singer.com/en-ca/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="es-us"
    href="https://www.singer.com/es/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="es"
    href="https://www.singer.com/es/pages/pfaff" />

    {% comment %} UK {% endcomment %}
  <link
    rel="alternate"
    hreflang="en-gb"
    href="https://uk.singer.com/pages/pfaff" />

    {% comment %} Europe {% endcomment %}
  <link
    rel="alternate"
    hreflang="de-at"
    href="https://europe.singer.com/de-at/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="cs-cz"
    href="https://europe.singer.com/cs-cz/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="da-dk"
    href="https://europe.singer.com/da-dk/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="fi-fi"
    href="https://europe.singer.com/fi-fi/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="de"
    href="https://europe.singer.com/de/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="en-de"
    href="https://europe.singer.com/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="it-it"
    href="https://europe.singer.com/it-it/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="no-no"
    href="https://europe.singer.com/no-no/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="es-es"
    href="https://europe.singer.com/es-es/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="sv-se"
    href="https://europe.singer.com/sv-se/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="de-ch"
    href="https://europe.singer.com/de-ch/pages/pfaff" />
  <link
    rel="alternate"
    hreflang="en-eu"
    href="https://europe.singer.com/pages/pfaff" />

{% elsif page.handle == 'husqvarnaviking' %}
  {% comment %} X-Default {% endcomment %}
  <link
    rel="alternate"
    hreflang="x-default"
    href="https://www.singer.com/pages/husqvarnaviking" />

    {% comment %} North America {% endcomment %}
  <link
    rel="alternate"
    hreflang="fr-ca"
    href="https://www.singer.com/fr-ca/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="en-us"
    href="https://www.singer.com/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="en-ca"
    href="https://www.singer.com/en-ca/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="es-us"
    href="https://www.singer.com/es/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="es"
    href="https://www.singer.com/es/pages/husqvarnaviking" />

    {% comment %} UK {% endcomment %}
  <link
    rel="alternate"
    hreflang="en-gb"
    href="https://uk.singer.com/pages/husqvarnaviking" />

    {% comment %} Europe {% endcomment %}
  <link
    rel="alternate"
    hreflang="de-at"
    href="https://europe.singer.com/de-at/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="cs-cz"
    href="https://europe.singer.com/cs-cz/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="da-dk"
    href="https://europe.singer.com/da-dk/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="fi-fi"
    href="https://europe.singer.com/fi-fi/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="de"
    href="https://europe.singer.com/de/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="en-de"
    href="https://europe.singer.com/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="it-it"
    href="https://europe.singer.com/it-it/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="no-no"
    href="https://europe.singer.com/no-no/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="es-es"
    href="https://europe.singer.com/es-es/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="sv-se"
    href="https://europe.singer.com/sv-se/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="de-ch"
    href="https://europe.singer.com/de-ch/pages/husqvarnaviking" />
  <link
    rel="alternate"
    hreflang="en-eu"
    href="https://europe.singer.com/pages/husqvarnaviking" />

{% else %}
  {% comment %} X-Default {% endcomment %}
  <link
    rel="alternate"
    hreflang="x-default"
    href="https://www.singer.com{{ request.path }}" />
{% endif %}

I’ve noticed that all the link tags in your snippet have a closing slash ( />), while the one rendered in the HTML code does not (>), so I believe the link element that is being rendered does not come from your snippet.

It would be helpful adding some HTML comments to determine which block of code from the if/elsif/else conditions is rendering (if any).

{%- if template.name == "index" -%}