Setting canonical & hreflang tags in multisite

I’m working as Freelance SEO Manager, and I’m currently trying to set the canonical tag on a recently translated website (German and English version) in the right formatting. Currently, the canonical is set as:

This technically works, but it’s not adding the pagination (e.g.: ?page=4) at all. Which is an issue for this website.

I also don’t know which parameters to use, so that the information for the hreflang element for the locale and the url are getting populated correctly.

Does anyone know with which code I can achieve that the canonical is getting generated incl. pagination and how to populate the information about the de, en and url for the hreflang tags?

Hi and welcome @dmdennislive

From what I gather, it’s missing the existing get params, is that correct?

Can you show the Twig code you are using to implement the tags? That would help us understand the issue better.


Hey daft,

thank you so much for your response! I realized that the code from the initial post got removed. Let me try again, currently, I have only added the following code into the “head” partial of the page.

<link rel="canonical" href="{{ url_current() | lower }}" />

This is the part that’s populating the canonical in the website’s html, without the pagination. For example:

<link rel="canonical" href="" />

But not

<link rel="canonical" href="" />

Additionally, I’d like to add the following hreflang tags but don’t know how to populate the information for the hreflang and href elements for each version.

<link rel="alternate" hreflang="de" href="" />
<link rel="alternate" hreflang="en" href="" />

So, yes, I think it’s missing the right get params. :slight_smile:

You can use url_full() to have the query strings included:
<link rel="canonical" href="{{ url_full()|lower }}" />

For the hreflang tags, we use this:

{% for site in sitePicker.sites %}
    <link rel="alternate" hreflang="{{ site.locale }}" href="{{ site.url }}" />
{% endfor %}

This works perfectly for me too, thank you so much!!