Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulziibat-n/e879c1c74b404d2120fe9623cf4e2bee to your computer and use it in GitHub Desktop.
Save ulziibat-n/e879c1c74b404d2120fe9623cf4e2bee to your computer and use it in GitHub Desktop.
Polylang shortcode for lang switcher
<?php
/**
* Polylang Shortcode - https://wordpress.org/plugins/polylang/
* Add this code in your functions.php
* Put shortcode [polylang_langswitcher] to post/page for display flags
*
* @return string
*/
function custom_polylang_langswitcher() {
$output = '';
if ( function_exists( 'pll_the_languages' ) ) {
$args = [
'show_flags' => 0,
'show_names' => 1,
'echo' => 0,
];
$output = '<ul class="polylang_langswitcher">'.pll_the_languages( $args ). '</ul>';
}
return $output;
}
add_shortcode( 'polylang_langswitcher', 'custom_polylang_langswitcher' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment