Use custom language code (URL, lang and hreflang attribute)
Here, we explain how to change the default language code. This is useful if you don't like the default 2 letters code of Weglot in the URL and want to change it into another language code.
Example: Changing "tw" to "zh-HK"
In this post, we show for example how to change language code tw (Traditional Chinese) to zh-HK (Hong Kong Chinese).
Hook for customize language code
This hook must be load before your theme. This is why you can not use it in your functions.php
. To use it, you can follow one of the 2 method below.
Update for autoredirection option
If you've activate the autoredirection option, you should be use this other filter to add your custom code into the navigator language list
Method 1: Use plugin Code Snippets
Add and activate Code Snippets plugin on your WordPress: https://wordpress.org/plugins/code-snippets/
In your WordPress back office, go to Snippets -> Add new
Add a title (example:
Weglot - Custom language code
)Add the following code into the code input. Don't copy
<?php
cause it's already added by the plugin.Save changes
Method 2: Create a MU-PLUGIN
Create a new file :
/wp-content/mu-plugins/weglot-language-code-replace.php
Add the following code into the new file and save it.
Last updated