How to implement hreflang?

Dear all,

I would like to create a multilingual website and wanted to know how to implemnent the hreflang tag

into the header.

Thanks in advance,
Oliver

Here’s how to implement multi language

I don’t think it adds that tag and attribute though.

It does populate the “lang” attribute in the html tag.

Hi Rod,

thank you for the link! I had tried this times ago, but had in terms of SEO not the desired success
So I want to create a multilanguage site after google specs, see: https://developers.google.com/search/docs/advanced/crawling/managing-multi-regional-sites

That means to create one folder per language and link it with the hreflang tag which should be implemented into the header (if I understand correctly)

Best regards,
Oliver

I can’t think of any easy/efficient way of doing that.

You could use phplugins to add the property/attribute to the <head> tag but if you’re doing this for multi language seo, then you would probably need to create a parallel site for each language.

Rod, thank you for your reply!
Thats what I wanted to do, creating a parallel site for each language.
And how to implement the following with phplugins???

link rel=“alternate” hreflang=“x-default” href=“mysite.com”/>
link rel=“alternate” hreflang=“de” href=“mysite.com/de”/>
link rel=“alternate” hreflang=“es-ES” href=“mysite.com/es”/>

Best regards,
Oliver

Use the phplugins “head” hook

You will need to implement phplugins for each of the sites you create, adding the appropriate language reference attribute in the head to each.

Ok, thank you very much, I will try that :slight_smile:

Best regards,
Oliver

I just read up on hreflang. From what I gather, it’s used to reference the visitor to another site in their own language. Is that right?

Yes and it should prevent duplicate content. :thinking:

Looks to me that you might need complete, separate sites for each language.
Or maybe just separate home pages for each?

1 Like

Youre right, unfortunately complete separate sites :frowning:

Hi,
I tried to add the hreflang tag to the header via phplugins, but it doesn’t work as it looks on the screenshot.
Screenshot 2022-01-25 184208

Can someone help me with this? :pray:

Thx in advance,
Oliver

The code looks fine to me.

did you start with the phplugins-pangolin-sample.php file?

Is the function you’re adding in the User Functions area of that file?

And have you enabled phplugins and chosen the correct file in the Advanced Setup area of the page template?

first thing to try is putting the parentheses directly after the hook name:
function head() {

Hi Rod,
yes I`m using phplugins-pangolin-sample.php and I enabled phplugins and it is in the user function area:


*> *
> first thing to try is putting the parentheses directly after the hook name:
> function head() {

Do you mean deleting the echo ’ ???

Ohhh, sorry, I think I got it…

Yes, I did not delete the underscores left and right of head
now it works :slight_smile: