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 id=”flags_language_selector”>
<?phplanguage_selector_flags(); ?>
</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;orderby=code');
    if(!empty($languages)){
        foreach($languages as $l){
            if(!$l['active']) echo '&amp;amp;amp;lt;a href="'.$l['url'].'"&amp;amp;amp;gt;';
            echo '&amp;amp;amp;lt;span&amp;amp;amp;gt;'.$l['language_code'].'&amp;amp;amp;lt;/span&amp;amp;amp;gt;';
            if(!$l['active']) echo '&amp;amp;amp;lt;/a&amp;amp;amp;gt;';
        }
    }
}

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

<div id=”flags_language_selector”>
<?phplanguage_selector_flags(); ?>
</div>

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;orderby=code');
  if(!empty($languages)){
    echo '&amp;amp;amp;lt;select onchange="if (this.value) window.location.href=this.value"&amp;amp;amp;gt;';
      foreach($languages as $l){
          if($l['active']) echo '&amp;amp;amp;lt;option value="'.$l['url'].'" selected &amp;amp;amp;gt;'.$l['language_code'].'&amp;amp;amp;lt;/option&amp;amp;amp;gt;';
          else echo '&amp;amp;amp;lt;option value="'.$l['url'].'"&amp;amp;amp;gt;'.$l['language_code'].'&amp;amp;amp;lt;/option&amp;amp;amp;gt;';
      }
      echo '&amp;amp;amp;lt;/select&amp;amp;amp;gt;';
  }
}

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

<div id=”flags_language_selector”>
<?phplanguage_selector_flags(); ?>
</div>