WPML | Custom languages selector

For a project, i need to develop a custom wpml languages selector:

For selector with languages flags only, add this directly in function.php of you theme.

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0&orderby=code');
    if(!empty($languages)){
        foreach($languages as $l){
            if(!$l['active']) echo '<a href="'.$l['url'].'">';
            echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
            if(!$l['active']) echo '</a>';
        }
    }
}

and this in your theme template where you want the selector appears :

</div>
<div>&lt;div id="flags_language_selector"&gt;</div>
<div>&lt;?php language_selector_flags(); ?&gt;</div>
<div>&lt;/div&gt;</div>
<div>

For Selector with languages code only, add this directly in you function.php

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0&amp;amp;amp;amp;amp;amp;orderby=code');
    if(!empty($languages)){
        foreach($languages as $l){
            if(!$l['active']) echo '&lt;a href="'.$l['url'].'"&gt;';
            echo '&lt;span&gt;'.$l['language_code'].'&lt;/span&gt;';
            if(!$l['active']) echo '&lt;/a&gt;';
        }
    }
}

and this in your theme template where you want the selector appears :

</div>
<div>&lt;div id="flags_language_selector"&gt;</div>
<div>&lt;?php language_selector_flags(); ?&gt;</div>
<div>&lt;/div&gt;

For selector with select box with language code. add this directly in you function.php

function language_selector_flags(){
  $languages = icl_get_languages('skip_missing=0&amp;amp;amp;amp;amp;amp;orderby=code');
  if(!empty($languages)){
    echo '&lt;select onchange="if (this.value) window.location.href=this.value"&gt;';
      foreach($languages as $l){
          if($l['active']) echo '&lt;option value="'.$l['url'].'" selected &gt;'.$l['language_code'].'&lt;/option&gt;';
          else echo '&lt;option value="'.$l['url'].'"&gt;'.$l['language_code'].'&lt;/option&gt;';
      }
      echo '&lt;/select&gt;';
  }
}

and this in your theme template where you want the selector appears :

&lt;div id="flags_language_selector"&gt;</div>
<div>&lt;?php language_selector_flags();  ?&gt;</div>
<div>&lt;/div&gt;