WPML: Custom Language Switcher

WPML: Custom Language Switcher

Quick reference on how to add custom language switcher in WPML


if(!function_exists('icl_post_languages')) {
	function icl_post_languages(){
	  $languages = icl_get_languages('skip_missing=1');
          echo '<pre>';
          var_dump($languages);
          echo '</pre>';
	  if(1 < count($languages)){
              // iterate through the list to create your custom language switcher
	  }
	}
}
/*
array(2) 
{ 
	["ms"]=> array(12) 
	{ 
		["code"]=> string(2) "ms" 
		["id"]=> string(2) "64" 
		["native_name"]=> string(6) "Melayu" 
		["major"]=> string(1) "0" 
		["active"]=> string(1) "1" 
		["default_locale"]=> string(5) "ms_MY" 
		["encode_url"]=> string(1) "0" 
		["tag"]=> string(5) "ms-MY" 
		["translated_name"]=> string(6) "Melayu" 
		["url"]=> string(26) "http://localhost/" 
		["country_flag_url"]=> string(88) "http://localhost/wp-content/plugins/sitepress-multilingual-cms/res/flags/ms.png" 
		["language_code"]=> string(2) "ms" 
	} 
	["en"]=> array(12) 
	{ 
		["code"]=> string(2) "en" 
		["id"]=> string(1) "1" 
		["native_name"]=> string(7) "English" 
		["major"]=> string(1) "1" 
		["active"]=> int(0) 
		["default_locale"]=> string(5) "en_US" 
		["encode_url"]=> string(1) "0" 
		["tag"]=> string(5) "en-US" 
		["translated_name"]=> string(7) "English" 
		["url"]=> string(29) "http://localhost/en/" 
		["country_flag_url"]=> string(88) "http://localhost/wp-content/plugins/sitepress-multilingual-cms/res/flags/en.png" 
		["language_code"]=> string(2) "en" 
	} 
}
*/

Reference: Custom Language Switcher

Leave a Reply

Your email address will not be published. Required fields are marked *

four × three =