Site logo

[Resolved] Change HTML lang

Home Forums Support [Resolved] Change HTML lang

Home Forums Support Change HTML lang

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2089549
    A. R. Choudhury

    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.

    #2089920
    David
    Staff
    Customer Support

    Hi there,

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

    #2090258
    A. R. Choudhury

    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”?

    #2090494
    David
    Staff
    Customer Support

    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;
    });
    #2090509
    A. R. Choudhury

    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?

    #2090897
    David
    Staff
    Customer Support

    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.

    #2091224
    A. R. Choudhury

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

    #2091267
    Elvin
    Staff
    Customer Support

    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/

    #2091272
    A. R. Choudhury

    Ok, Elvin. Thanks.

    #2091273
    Elvin
    Staff
    Customer Support

    No problem. 😀

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.