Skip to content

Instantly share code, notes, and snippets.

@Jany-M
Created August 26, 2015 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jany-M/2ac6bffb6fb25f1c1a22 to your computer and use it in GitHub Desktop.
Save Jany-M/2ac6bffb6fb25f1c1a22 to your computer and use it in GitHub Desktop.
[WordPress] WPML custom language selector for dsIDXpress IDX plugin compatibility
<?php
// Custom Lang Selector
if (function_exists('icl_get_languages')) {
// Get Native Lang Name
function get_language_name($code=''){
global $sitepress;
$details = $sitepress->get_language_details($code);
$language_name = $details['display_name']; // options are: english_name / display_name
return $language_name;
}
// The Selector
function languages_list_header() {
$languages = icl_get_languages('skip_missing=0&orderby=custom');
if(!empty($languages)){
foreach($languages as $l) {
if($l['active'] == '1') {
$active_class = ' active';
} else {
$active_class = '';
}
if(is_page_template('template-idx.php') && $l['active'] != '1') {
echo '<li><a class="btn'.$active_class.'" href="'.$l['url'].str_replace('/'.ICL_LANGUAGE_CODE.'/', '', $_SERVER["REQUEST_URI"]).'" title="'.get_language_name($l['language_code']).'" role="button">'.$l['language_code'].'</a></li>';
} else {
echo '<li><a class="btn'.$active_class.'" href="'.$l['url'].'" title="'.get_language_name($l['language_code']).'" role="button">'.$l['language_code'].'</a></li>';
}
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment