Add language attribute to header


#1

Hi
I have a com site, which is actually only for norweigan users. How can I add the lang=“no” attribute to the header of this domains pages?
I can’t seem to get it working with either:
document.documentElement.setAttribute(“lang”, “no”);
or as
$(“html”).attr(“lang”, “no”);
Can you provide any help or guidelines for setting the language in the global scripts?
Best regards
Lars


#2

I want to know as well


#3

Hi guys, 

Here is a piece of JS that should help you (set the placement to “Head”):

&nbsp; <br />document.getElementsByTagName("html")[0].setAttribute("lang", "no");<br />

Best,
Hristian


#4

Hi Hristian - thanks a lot for your reply.
Unfortunately it didn’t help. I went to the script manager to place it in the head script for all main pages for the domain. The script is placed in the header, but seem not to work.
Best regards
Lars


#5

Hi Lars, 

This is strange since the script works when I test it. 

Here are a couple of screenshots of a test page I set up (Chrome & Firefox). Chrome even detects that the language is set to “no” and asks if you want to translate it. 

Best,
Hristian


#6

Hi, is anybody managed to do that with the code shared by Hristian?
I put it in the header and republish my page, but I still can’t see the language tag in my Header.

Best.


#7

Hi @tunedglobal,

My script above got broken when Unbounce switched the community platforms last year.

Here is the script you need to use.

Here you can see it working on a demo page.

Best,
Hristian


#8

Thanks Hristian, it works!