S tep 2: Now we write a shortcode for displaying above countries. But before that, under “ WPML > Languages” menu there is an option for setting language URL format. add_shortcode('wpts_countries','wpts_countries') This option is for configuring which URL format should be used to display language specific content and three URL formats are available,įor this article purpose, we are using 1 st option. The above code section declares a shortcode for displaying simple country dropdown. The global variable “ ICL_LANGUAGE_CODE” is WPML specific global variable which contains current language selection, which means if the English language is selected, ICL_LANGUAGE_ CODE variable will contain value “en”’ and so on. $countries = unserialize(WPTS_COUNTRIES) Un-serialze global constant WPTS_COUNTRIES The function getContryDropDown is defined as below, function getContryDropDown($lang = null) In above function, first, we unserialize global constant WPTS_COUNTRIES and store into $countries variable as an array. #WPML CUSTOM LANGUAGE SWITCHER SHORTCODE CODE#Īfter that, we retrieve the corresponding list of countries in switch statement for selected language code ($lang) passed as parameter and store that list in variable $show_countries.Īfter retrieving language list we loop through the array to build a drop-down box as shown is above code snippet. Now Let’s create a page and put shortcode on that page.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |