I didn’t find a suitable WordPress plugin for this, because they usually do much more and introduce a whole translation management solution. Including changing all URLs across the whole site.

So let’s KISS – keep it simple and stupid!

Yet another WordPress Plugin: «Language Locale Overwrite»

Why not publish this to the world – when I have already created and using it? 😎

There’s a somewhat comprehensive README in the repository

What does this WordPress Plugin do?

Changing the HTML lang attribute in WordPress

While tackling some search engine optimizations of this blog, I wanted to fix two things:

  1. First, «globally»: the blog should indicate a «neutral English» (en) language – instead of specifically «English (United States)» (en-US).
Screenshot of Language Overwrite for whole Site using my WordPress Plugin
  1. Second, «per Post(s)»: so that I can properly tag the correct language on some single posts, written in German in early days of this blog, with the language attribute «German» (de).
Screenshot of a Language Overwrite for single Posts Pages using my WordPress Plugin
  1. And last but not least, «Alternate Hreflang metatags»: easily allow selecting translated Posts / Pages, so that they are referenced properly using SEO alternate hreflang tags.
Screenshot of Language Overwrite showing Alternate Hreflang metatags to translated Posts

How can the Plugin be used?

As this is not an officially published Plugin on the WordPress Plugin directory, please follow the instructions as documented on the GitHub project:

Once installed and set-up, there’s a new section in the WordPress “Settings » General” to change global language settings, and within the Block Editor to change a Post’s/Page’s HTML lang attribute.

I hope this helps somebody who might have the same situation with multiple language posts in their WordPress blog.

Share:
  • 6
  • 3

6 thoughts on “Change HTML lang & add alternate hreflang links to WordPress blogs”

  1. Hi !

    Thanks for the share – your plugin is exactly what I needed !
    But … something’s wrong as I try to use it (version 2.0.0) :
    on the bottom of my pages, I see Language Locale section and i can choose language… but alternate link section looks like this, with the error message :

    Warning: array_unique() expects parameter 1 to be array, null given in /var/www/kamelecom.com/padel/wp-content/plugins/language-locale-overwrite-2.0.0/language-locale-overwrite.php on line 255

    Warning: Invalid argument supplied for foreach() in /var/www/kamelecom.com/padel/wp-content/plugins/language-locale-overwrite-2.0.0/language-locale-overwrite.php on line 164

    How to fix it to use it to also choose alternate links ?

    Thanks for help

  2. Hi, thanks for plugin! Its fantastic.

    I have site with native lng – en-US and I need add some ua pages….. So, I add ua page in section «Language Locale» set – uk_UA and for native EN page set – en-US… updated and this: “use the «Link alternate lang…»-dropdowns to make cross-links” – dropdowns not exist…. I slso try clear en-US for native lng page…. result same….. Where I’m wrong? Thanks

    1. Hi Dmytro,
      It‘s hard to tell why that’s not working for you. One thing: try adding en-UA (instead of uk-UA, as this seems not a valid language-Country code…).

      And make sure you use the newest version.

  3. Hello Oliver!

    Thank you so much for your great plugin! I don’t see the “dropdowns to make cross-links”. Any idea why?

    Here is my setting :

    1.
    I have added the WordPress Language Locale override codes
    – Change HTML lang attribute : fr
    – Custom Country code : FR

    2.
    In my 2 connected pages (I have only done the test on 2 pages so far). In the first page (the french version), I have set “fr” in Language Locale, and in the second page (the english version), I have set “en-GB” in Language Locale.

    Well, I don’t see any dropdown to connect the 2 pages 😉 Could you clarify the process? Thank you for your help!

    1. Hi Geraldine,
      Thanks for your feedback.

      Can you elaborate if you are working on „Pages“ or „(Blog) Posts“ – and do you know if the ones where you set a custom locale are Default Page/Post types which are included by default in WordPress; or „custom types“ added by you / the theme you are using?

      Because for the later, that’d be a known issue as described here: Issue #3 : language selector doesn’t appear on custom post types created using Advanced Custom Fields plugin

      Cheers

Questions? Suggestions? Let us know with a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.