Language functionality and hreflang tag

Hi,

I read on Multi-language Content - HubSpot docs that Hubspot default multi-language functionality automatically adds an hreflang tag tag to the pages with a choosen language:

<link rel="alternate" hreflang="lang_code" href="url_of_page" />

However, is it possible to add this tag dynamically to the header of a theme if not used the language variation functionality?

Lets say that I have 3 websites (3 different subdomains) called:

https://english.domain.com

https://spanish.domain.com

https://german.domain.com

They all use the same shared design theme/templates.

How can I add/code a dynamic hreflang tag for all websites in my shared theme?

The only tag I have right now is:

<html lang="{{ html_lang }}" {{ html_lang_dir }}>

but that does not add the hreflang tag.

Thanks

Hi, @TomasCarlsson :waving_hand: Thanks for the question! Hey, @assi @BarryGrennan, do you have any experience here? Or thoughts on how @TomasCarlsson might approach this?

Thank you! — Jaycee

Hi @TomasCarlsson ,

you could do something like this:

{% set href_plain = '//' ~ request.domain ~ '/' %}

<link rel="alternate" hreflang="en" href="{{ href_plain }} ~ /en" />
<link rel="alternate" hreflang="es" href="{{ href_plain }} ~ /es" />
<link rel="alternate" hreflang="pt" href="{{ href_plain }} ~ /pt" />