Streaming live at 10am (PST)

Language attribute on a collection page

I want to use a collection for multiple languages. Everything is quite easy to set up and you can add different meta for each page, that’s awesome. Also easy to maintain design wise and through the editor. But what about the language attribute, how could we add that?

Is it possible to add that with JS, If so can some with right skills give the code needed?

Thanks for your help!

@jorn take a look at this link Set language of document

1 Like

That piece of code might just work. Thanks Janne!

It works! I added this code to my Collection page before end of body:

 $(document).ready(function() {

And used Add Field functionality from my collection to dynamically add the language code needed. My published page now shows the correct language attribute inside the html tag.

Curios if anyone sees any problem with this SEO wise?
Each item(page) in the collection will have their own language, meta title and description in their own language and the right language attribute. Only problem I can see is the URL’s. It would maybe be better to have folders named /sv and /en and so on but besides from that…

1 Like

Good question on SEO.
Any update on this? Does google crawler understand the new language even tho’ the language switch is down in script tag?

You can try using Google URL inspection tool (Search Console) to view the rendered source.
If the lang-attribute is shown in the rendered HTML, there should be no SEO issue.