Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide language WPML

I am using WPML language, and cant find solution for next thing:

On the Language switcher i want to hide language, lets say for example - "he", if current language is lets say for example "ar", so when we on arabic site we will not see on the selector the Hebrew, and same thing if we on Hebrew, the arabic will not display.

On shorten words: what i want is - if we on arabic site - the hebrew flag will be hidden.

What i tried:

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0');
    if(!empty($languages)){
       if(ICL_LANGUAGE_CODE=='en') 
       {
$order = array('ar'); //Specify your sort order here
       }
elseif(ICL_LANGUAGE_CODE=='he')
{
$order = array('en', 'ar'); //Specify your sort order here
}

        foreach ($order as $l) {
            if (isset($languages[$l])) {
                $l = $languages[$l]; //grab this language from the unsorted array that is returned by icl_get_languages()

                //Display whatever way you want -- I'm just displaying flags in anchors  (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
                if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
                echo '<a '.$url.' style="background:url('.$l['country_flag_url'].') no-repeat;" class="flag '.$class.'">';
                echo $l['language_code'].'';
            }
        }
    }
}

Its not affect at all the selector.

like image 566
Oshrib Avatar asked Dec 03 '13 08:12

Oshrib


2 Answers

You can check out the plugin WPML Flag In Menu.

You could use the plugin_wpml_flag_in_menu() function from the plugin (see source code here) and replace:

// Exclude current viewing language             
if( $l['language_code'] != ICL_LANGUAGE_CODE )
{
    // ...
}

with

// Include only the current language                
if( $l['language_code'] == ICL_LANGUAGE_CODE )
{
    // ...
}

to show only the current language/flag, if I understand you correctly.

ps: If you need further assistance, you could for exampe show us the output of this debug function for the active language:

function debug_icl_active_language()
{
    $languages = icl_get_languages( 'skip_missing=0' );
    foreach( (array) $languages as $l )
    {
        if( $l['active'] )
        { 
            printf( '<pre> Total languages: %d - Active: %s </pre>', 
                    count( $languages ), 
                    print_r( $l, TRUE ) );
        }
    }
}
like image 159
birgire Avatar answered Nov 06 '22 22:11

birgire


i have some useful link for you, please go through it first:

http://wpml.org/forums/topic/hide-language-vs-display-hidden-languages-in-your-profile-not-working/

http://wpml.org/forums/topic/hide-one-language/

http://wpml.org/forums/topic/hiding-active-language-in-menu/

http://wpml.org/forums/topic/language-selector-how-to-hide-one-language/

thanks

like image 39
Krunal Shah Avatar answered Nov 06 '22 22:11

Krunal Shah