This is my code,add the code in your file functions.php
, and then add shortcode
in the place where you want to show the list of languages it shows the languages in the form of a country flag, you can show what you want just remove a comment on a var_dump
.then edit it as you like
<?php
/**
* Put shortcode [polylang_langswitcher] to post/page for display flags
*/
function custom_polylang_langswitcher() {
$langs_array = pll_the_languages( array( 'dropdown' => 1, 'hide_current' => 0, 'raw' => 1 ) );
//var_dump($langs_array);
if ($langs_array) : ?>
<div class="drop-block lang">
<?php foreach ($langs_array as $lang) : ?>
<a href="<?php echo $lang['url']; ?>" class="drop-block__link icon-<?php echo $lang['slug']; ?>">
<img width="32" height="32" src="<?php echo $lang['flag']; ?>" alt="<?php echo $lang['slug']; ?>" />
</a>
<?php endforeach; ?>
</div>
<?php endif;
}
add_shortcode( 'polylang_langswitcher', 'custom_polylang_langswitcher' );
?>