Created
December 11, 2012 05:57
-
-
Save rolandinsh/4256221 to your computer and use it in GitHub Desktop.
WPML: default first in language switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Making the default first in WPML's language switcher | |
via http://rahmetli.info/en/making-the-default-first-in-wpmls-language-switcher/ | |
@Todo rolandinsh: clean-up and update | |
*/ | |
// Get language array | |
$list = icl_get_languages('skip_missing=1&orderby=id&order=asc'); | |
// Getting default language to first position | |
// Create a temporary array and hold its first position | |
$temp[0] = ''; | |
foreach($list as $l){ | |
if($l['language_code'] == 'tr') // Turkish is default | |
$temp[0] = $l; // assign default language to first position of temp array | |
else | |
array_push($temp, $l); // push other languages to temp | |
} | |
// change original with temp, then remove temp | |
$list = $temp; | |
unset($temp); | |
// print links (you can use your own style) | |
$print = '<ul class="myLanguageSwitcher">'."\n"; | |
$c = count($list); // count languages | |
for($i=0;$i<count($list);$i++){ | |
// if the language is active, insert the class "active" | |
$print .= '<li class="'.(($list[$i]['active']=='1')?'active':''); | |
// if it's the last language in array, insert the class 'noBackground' | |
if($i == $c - 1) | |
$print .= ' noBackground'; | |
// create link of language with native name | |
$print .= '"><a title="'.$list[$i]['native_name'].'" href="'.$list[$i]['url'].'">'; | |
$print .= $list[$i]['native_name']; | |
$print .= '</a></li>'."\n"; | |
} | |
$print .= '</ul>' | |
echo $print; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment