How to change language code in WPML

WPML is considered one of the most well loved plugin to manage Multi language WordPress sites. Due to its stability and security, it’s no surprise that WPML powers over a million websites. But learning and WPML is not exactly a walk in the park. And one of the most common problems that users face is in changing the default language slug.

A google search on “wpml change language slug” reveals pages after pages of support requests asking for ways to do this. Like this and this. The solution, however, has always been vague. In this guide, we will illustrate step by step a really simple way to change a Language slug.

WPML Language Code Slug

WPML has 3 URL options to distinguish languages. To choose your preferred method Go to “Languages” in the WPML section of your WordPress Dashboard. In the “Language URL format” section, you’ll be presented with 3 different options.

WPML URL format

  1. Different languages in directories
  2. A different domain per language
  3. Language name added as a parameter

If you choose to use option number 1 or 3, WPML will use your URLs like these:

Option 1: https://www.example.com/zh-hans/ or Option 3: https://www.example.com?lang=zh-hans

zh-hans” is the language code for Simplified Chinese. Which we will use as our example.

Now, what we want to do is to replace the language code, “zh-hans” portion of the URL so that it looks more memorable. In this example, our desired slug will be https://www.example.com/cn/. 

Lets begin.

1. Go to Languages Panel

Look for “Site Languages“. Here you’ll see all your chosen languages you have chosen.

WPML Site Languages

2. Click on Edit Languages

Here, you’ll see the settings of the languages that you have selected for your site.

WPML Language code

Now, lets take a look at the “code” column. We see our target language “Chinese (Simplified)” but there’s no way we can change the “zh-hans” code.

3. Click on Add Language

Now, add a language by duplicating the same values of the original language. Note that we want to retain the locale and hreflang values. These values are important as these represents a standard country and language codes. Please do not input a random made up code. You can read more on hreflang codes here and here.

WPML Add language error

When you click save, you’ll encounter many errors such as “duplicated language name” etc. To resolve these errors, we’ll simply change the Language name of the new entry to “Chinese“. And don’t forget, our objective is to change the language code. So in the “code” column, we’ll input “cn“.

Lastly, we’ll change the Original Default Locale and hreflang. Say “zh_CN1” and “zh-hans1“. Doesn’t matter what the value is as we won’t be using the original default language. You should be able to save now.

WPML add language Success

4. Remove unused language

Lastly, we need to remove the unused language. Navigate back to “Site Languages” and on “Add/Remove Languages“. In this case, uncheck “Chinese (Simplified)“. Save.

WPML remove language

5. Verify the changes

Scroll down a little bit to verify that the changes are made correctly.

WPML edited Language list

Additionally, you may want to review the code source. Visit your language page and view source. In the meta code you should see your hreflang language meta tag like so:

<link rel="alternate" hreflang="zh-hans" href="https://www.example.com/cn/" />

And we’re done.

Conclusion: WPML Change Code and Slug

We hope that this really simple walkthrough have helped you in changing your website’s language code to achieve you desired slug.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments