

This array is then serialized and stored into constant variable.Įnglish (en), French(fr), Italian(it), German (de) and Spanish (es) speaking country list is stored in an array. In the code snippet below, an array is defined with indexes as languages codes and with sub-array with countries speaking that particular language. We can store countries in the database table and build CRUD around it but I would keep things simple for this article.

In the Child themes functions.php file, let’s define a constant for storing a list of countries.

Step 1: First of all we will create a shortcode to display countries on a page. To achieve this we need to write custom code in functions.php file of “Child theme”, in our case it’s Twenty Sixteen child theme. What we want is to make countries drop down shown according to the language selected in language switcher.įor e.g let’s say if we select the French language, the country dropdown should be populated with French-speaking countries, for German language German speaking countries should be populated and so on.
Wpml language switcher how to#
Now as shown in Screenshot 1, country drop down shows all the list of the countries populated (I will go through how to populate this dropdown field). We show the switcher in “ Theme sidebar” and here is a screenshot of the what language dropdown looks like. Multilingual Plugin WPML is installed and is configured for following languages,Īnd under “ WPML > Languages” menu there is “ Language switcher options” section where the Language switcher can be shown in many places in the theme.
Wpml language switcher update#
We want to update countries list in a drop-down box, according to WPML Language switcher i.e whenever the Language in “WPML Language switcher” is changed the country drop down will display all the countries speaking that specific selected language. The situation for this article is, let’s say we have the country list displayed in a drop down as shown in Screenshot 1 and also WPML Plugin is installed and configured for five different Languages as shown in Screenshot 2.
