Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Last active October 23, 2017 13:05
Show Gist options
  • Save thierrypigot/bc711705e377ae722de8f9125af64969 to your computer and use it in GitHub Desktop.
Save thierrypigot/bc711705e377ae722de8f9125af64969 to your computer and use it in GitHub Desktop.
Shortcode pour afficher la liste des drapeaux Polylang
<?php
add_shortcode('polylang', 'wearewp_shortcode_pll_the_languages');
function wearewp_shortcode_pll_the_languages() {
if( function_exists('pll_the_languages') ) {
global $post;
$args = array(
'show_flags' => 0,
'hide_if_empty' => 0,
'show_names' => 1,
'display_names_as' => 'slug',
'echo' => 0,
'hide_current' => 0,
'force_home' => 0,
'raw' => 1,
);
$langs = pll_the_languages($args);
if( $langs ) {
$html = '<ul class="nopadding">';
foreach ($langs as $langue) {
if( $langue['current_lang'] ) {
$html .= '<li class="active"><a class="text-white small">'. $langue['name'] .'</a></li>';
} else {
$html .= '<li><a href="'. $langue['url'] .'" class="text-white small">'. $langue['name'] .'</a></li>';
}
}
$html .= '</ul>';
return $html;
} else {
return false;
}
}
}
<?php
add_shortcode('polylang', 'tp_shortcode_pll_the_languages');
function tp_shortcode_pll_the_languages()
{
if( function_exists('pll_the_languages') ) {
$args = array(
'show_flags' => 1,
'show_names' => 0,
'echo' => 0,
'hide_current' => 1,
);
return '<ul>' . pll_the_languages($args) . '</ul>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment