Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Created April 23, 2014 11:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivandoric/11212191 to your computer and use it in GitHub Desktop.
Save ivandoric/11212191 to your computer and use it in GitHub Desktop.
wordpress: WPML Custom Language switcher
<?php
/*Just add this anywhere in yopur template where you want language switcher to appear.
This switcher just shows the flags. But you can make it work anyway you like */
?>
<ul class="lang-switcher">
<?php
$languages = icl_get_languages('skip_missing=N&orderby=KEY&order=DIR&link_empty_to=str');
foreach($languages as $language){
$flag = $language['country_flag_url'];
$url = $language['url'];
$isActive = $language['active'];
$name = $language['native_name']
?>
<li><a href="<?php echo $url; ?>" <?php if($isActive == 1){ ?> class="active" <?php } ?>>
<img src="<?php echo $flag; ?>" alt="<?php echo $name; ?>" />
</a></li>
<?php } ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment