Wordpress Polylang language dropdown switcher with flags only in widget

2.3k Views Asked by At

I use polylang plugin as the multilanguage solution for my website.

In my menu I use the polylang widget with Elementor builder. In the classic polylang menu made in your wordpress you could add polylang widget switcher where you could choose the option to display flags only. Problem is that I don't use menu widget switcher because I don't want to display switcher with the menu items but in my custom column of my header.

I use the Elementor's widget which is used in sidebars. But sidebar widget switcher does not have the option to display flags only in a dropdown menu. It displays only the language names with no option to display flags. What I need to do is to display flags only in my custom widget.

I have also tried this code but it is also showing only the language names and not flags.

function custom_polylang_langswitcher() {
    $output = '';
    if ( function_exists( 'pll_the_languages' ) ) {
        $args   = [
            'show_flags' => 1,
            'show_names' => 0,
            'echo'       => 0,
            'dropdown'   => 1,
        ];
        $output = '<ul class="polylang_langswitcher">'.pll_the_languages( $args ). '</ul>';
    }

    return $output;
}

add_shortcode( 'polylang_langswitcher', 'custom_polylang_langswitcher' );

Replace language names with flags. enter image description here

Thanks in advance for your help.

0

There are 0 best solutions below