Last active
April 20, 2025 09:29
-
-
Save taninbkk/f95281b44b3762435777 to your computer and use it in GitHub Desktop.
Polylang Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Polylang Shortcode - https://wordpress.org/plugins/polylang/ | |
// Add this code in your functions.php | |
// Put shortcode [polylang] to post/page for display flags | |
function polylang_shortcode() { | |
ob_start(); | |
pll_the_languages(array('show_flags'=>1,'show_names'=>0)); | |
$flags = ob_get_clean(); | |
return $flags; | |
} | |
add_shortcode( 'polylang', 'polylang_shortcode' ); |
To modify your polylang_shortcode so it:
1. Only shows languages other than the current one, and
2. Displays both flag and language name,
You can update the function like this:
function polylang_shortcode() {
ob_start();
pll_the_languages(array(
'dropdown' => 0,
'show_flags' => 1,
'show_names' => 1,
'hide_current' => 1, // Hides current language
'raw' => 0 // Output as HTML
));
return ob_get_clean();
}
add_shortcode('polylang', 'polylang_shortcode');
✅ Explanation:
• 'hide_current' => 1 – hides the current language.
• 'show_flags' => 1 – shows the language flag.
• 'show_names' => 1 – shows the language name.
• 'raw' => 0 – outputs HTML instead of raw array.
💡Usage:
Add [polylang] in any post, page, or widget, and it will display only the other available languages with both flag and name.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to set user wise [POLYLANG] in wordpress?