Search code examples
tagsaccessibilitykentico

Trouble implementing the language accessibility fix on a Kentico Site


As the title states I am having problems with this, Utilizing the code Brenden Kehren initally set forth from this thread: https://devnet.kentico.com/questions/kentico-9-how-to-define-language-in-html

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
    if (CurrentDocument != null)
    {          
        CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
        if (page != null)
        {
            string lang= CMS.Localization.LocalizationContext.CurrentCulture.CultureCode;
            page.XmlNamespace += " lang=\"" + lang + "\"";
            page.XmlNamespace += " xml:lang=\"" + lang + "\"";
        }
    }
}
</script>

however for the life of me I cannot seem to get it to work, keep on getting: Uncaught SyntaxError: Unexpected token void

At the line: protected void Page_Load(object sender, EventArgs e)

I have placed the code in the header of the master template, I open the Header Tab, And in the text box under where it says "Add HEAD element content:" I paste in the full snippet that was provided. Including the . Running Kentico 9 if that helps.

It just seems odd that I cannot get this to work. Any suggestions?

The site is multi cultural with an English and Spanish version, I thought Kentico was able to auto set up the Language tag in that case but apparently not.


Solution

  • If you place the script directly in the layout like this:

    script code in kentico

    It should have the following output: (before and after html)

    added language tags in html