Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/94cf10e49bb758d9cb2e to your computer and use it in GitHub Desktop.
Save krishna19/94cf10e49bb758d9cb2e to your computer and use it in GitHub Desktop.
/* 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