Site logo

Archived topic

Change HTML lang

9 replies · Started by A. R. Choudhury on January 22, 2022

Viewing posts 1–10 of 10

Hello, I want to launch a website in Bengali language. The best way is to install WP on a subdirectory and change the site language. I did that. But the problem is, the HTML language after changing the site language is "<html lang="bn-BD">"

It looks as if it is set only for Bangladesh region.

I want to change that to "<html lang="bn">"

How can I do that?

The English version of HTML language is also set to <html lang="en-US"

How can I change that too to <html lang="en"

Because I have noticed that major websites in my niche like Healthline, WebMD also uses <html lang="en">

Please help.

Hi there,

just to be clear you want to have the site displayed in Bengali but the Language meta to be set to English?

No no. For example, If I view the page source of GeneratePress, I can see the language HTML <!DOCTYPE html><html lang="en-US">

The same happened with all my sites.

I want to change the language of HTML to be <!DOCTYPE html><html lang="en">

See, HTML is not “en-US”. It is only “en”.

You can see for example here: view-source:https://www.healthline.com/

How can I change HTML language from “en-US” to “en”?

Then you would need a PHP Snippet as WP only adds languages and country.
Try adding this snippet:

add_filter('language_attributes', function($lang){
    $lang = "lang=\"en\"";
    return $lang;
});

Thanks, David. It works.
What about this plugin? https://wordpress.org/plugins/chl-change-html-lang/
Is it function like the same? I have tried this and it also works.
But it hasn’t been tested with the latest 3 major releases of WordPress.
Can I use it safely?

I can't say whether its safe for use but WP looking at the plugins code it uses the same language_attributes filter plus doing some stuff if WPSEO ( Yoast ) is active.

Ok. Is there any way to just change Site HTML Language without changing the WordPress dashboard language without plugins?

Hi there,

Ok. Is there any way to just change Site HTML Language without changing the WordPress dashboard language without plugins?

David's provided code from one of his previous reply does that.
https://generatepress.com/forums/topic/change-html-lang/#post-2090494

More about language_attributes filter here
https://developer.wordpress.org/reference/hooks/language_attributes/

If you wish to avoid adding even the Code Snippets plugin then you must have a child theme's functions.php.

Here's how to add PHP snippets - https://docs.generatepress.com/article/adding-php/

Ok, Elvin. Thanks.

No problem. :D

This archived topic is closed to new replies.