Topic: Define lang attribute in theme template

Language attribute or lang defines the base language used by the document in HTML document.
This is important because:

  • This attribute assist search engine and informs them about the language used in the web page. This can help search engines in filtering results based on the linguistic preferences of a user.

  • Speech synthesizers and Braille translators can use this information and make content of the web page more accessible. This information is required by the W3 WAI (Web accessibility Initiative) guidelines and is required by law for many public facing government websites in many countries.

  • Services like automatic spell checker, grammar checker and translation services can use this attribute to identify base language of the web page.

  • Another example of language-dependent behavior is hyphenation. Hyphenation rules are very language dependent. If you are using hyphens property in your CSS.

So, to add this to our theme template, matching our language settings in admin

<!DOCTYPE HTML>
<html lang="<?php echo substr($settings['language'], 0, -3); ?>">

We are using substr() to strip out the last 3 characters of the string because the lang attribute only accepts the 2 characters language code, but in our admin settings it is set using the lower and uppercase standard (eg: en_US).
The result:

<!DOCTYPE HTML>
<html lang="en">
Look out, there's a three headed monkey behind you!!

Re: Define lang attribute in theme template

Hello and thank you very much for this valuable input.
Could you please precise what piece of code must be inserted where and in which file so that this can be properly effected ?
Thank you for your help
Sincerely