0

I used below codes to to add a shortcode, and the css to style. Both working fine in This Website:

// PHP: Add this to your functions.php file

function polylang_flags_shortcode() {
ob_start();
pll_the_languages(array('show_flags'=>0,'show_names'=>1));
$flags = ob_get_clean();
return '<ul class="polylang-flags">' . $flags . '</ul>';
}
add_shortcode('POLYLANG', 'polylang_flags_shortcode');

/* CSS Polylang Flags/Names Inline */
.polylang-flags {
  list-style-type: none;
  margin: 0;
  padding: 0;
}
.polylang-flags li {
    display: inline;   
}

Now, I need to hide the current language.

Please advice on a code to add or modify.

Thanks

1

You need to add the hide_current parameter to this function. And when you use plugin function in your code, be sure to check if function exists. If the plugin get disabled, your website will continue to work :)

function polylang_flags_shortcode() {
    ob_start();
    if(function_exists('pll_the_languages'))
    {
        echo '<ul class="polylang-flags">';
        pll_the_languages(array(
            'show_flags'    => 0,
            'show_names'    => 1,
            'hide_current'  => 1,
        )); 
        echo '</ul>';
    }
    return ob_get_clean();
}
add_shortcode('POLYLANG', 'polylang_flags_shortcode');

I also move the ul part !

  • sorry to jump in, but how would i get the corresponding translated url? Now it just links to the homepage in the other language ( i just have 2 languages at the moment) – alex Aug 20 '18 at 7:53
  • The Polylang Flag system should gives you translations URL and if there is not, homepage url in other languages. Does it work for you ? – Elex Aug 26 '18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.