Setting a site's culture in Kentico 10 and the attribute lang="en" in the <html> tag

Heather Aluma asked on April 9, 2021 20:35

I want to set a language attribute to the html tag of a one-language website. Will setting the site's culture do this?

Recent Answers


Juraj Ondrus answered on April 12, 2021 06:05

The lang attribute is not included by default, but you can add it with the following approach:

  1. Make a copy of the following file ~/CMSPages/PortalTemplate.aspx, (for example, naming it something like CustomPortalTemplate.aspx)
  2. Edit the CustomPortalTemplate.aspx file
  3. In the <html> tag, add the following: lang = <% = Lang%>
  4. Edit the CustomPortalTemplate.aspx.cs file
  5. Add a Lang property: protected string Lang {get; set; }
  6. In the OnPreRender method, set the Lang property, for example based on the document culture: Lang = this.CurrentPage.DocumentCulture; (if you only want a 2-letter code, use CurrentPage.DocumentCulture.Substring (0, 2))

  7. Save the files and edit the main web.config file, adding the following key: <add key = "CMSPortalTemplatePage" value = "~/CMSPages/CustomPortalTemplate.aspx">

After these changes, you should see a lang attribute on all pages.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.