Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* Pierre de la Martinière
*
* display all languages avalaible for a Wordpress Theme using WPML
* directly echo something like "en fr it ru" ...
*
* more info at http://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/
*
*/
//[wpml_lang_selector]
function wpml_shortcode_func() {
if (function_exists('icl_get_languages')) {
$output = '';
$languages = icl_get_languages('skip_missing=0&orderby=id&order=asc');
$output .= '<div class="lang_selector">';
foreach($languages as $i=>$data):
if($data['language_code'] == ICL_LANGUAGE_CODE):
$output .= '<a class="active" href="'.$data['url'].'">'.$i.'</a>';
else :
$output .= '<a href="'.$data['url'].'">'.$i.'</a>';
endif;
endforeach;
$output .= '</div>';
return $output;
}
}
add_shortcode( 'wpml_lang_selector', 'wpml_shortcode_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.