0

This function is part of the WMPL-Plugin (Language-Selector) for Wordpress. What I need is a extension (if / else) of this function which makes it possible to show another flag-image on active sites.

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>';
        }
    }
}

The CSS isn't a problem, but my php-skills are on a very low level. It would be great if anyone can tell me a solution. Thanks for your helping me!

1 Answers1

0

I believe this should do the trick:

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'].'">';
            if($l['active']){
                echo '<img src="'.ACTIVE_FLAG_URL.'" height="12" alt="'.$l['language_code'].'" width="18" />';
            }else{
                echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />';
            }
            if(!$l['active']) echo '</a>';
        }
    }
}

You need to substitute "ACTIVE_FLAG_URL" with your own URL.

Luka Peharda
  • 1,003
  • 8
  • 18
  • Thanks, it works, but only if the active image is always the same. I think I need a modification of country_flag_url like country_flag_url +_active (= en_active.png, es_active_png ...) My problem is that country_flag_url includes the full file name (e.g. en.png) – mrs.yoda Sep 20 '13 at 21:41