• Hello,

    is it possible to display the international two-letter codes in the Polylang language switcher instead of the full language names?

    Deutsch >>> DE
    English >>> EN

    I used “WPML” before as a translation plugin but would like to switch to “Polylang”. “WPML” does have that feature which I find quite important.

    Any way I can achieve that in “Polylang” as well?

    Thanks and regards!
    Arne

    https://www.ads-software.com/plugins/polylang/

Viewing 7 replies - 1 through 7 (of 7 total)
  • anonymized-13603639

    (@anonymized-13603639)

    Yes, you can. Display slug instead of name. Or edit name from “English” to “EN”.

    Thread Starter Arne Teubel

    (@arnerobot)

    Hello,

    thanks for the help! I know how to edit the language names – great idea! But how can I change it to display the slug?

    Thank you and regards –
    Arne

    anonymized-13603639

    (@anonymized-13603639)

    Check out Polylang function reference at https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/

    As you can see pll_the_languages() allows you to use some arguments. With

    <?php pll_the_languages(array('display_names_as'=>'slug')); ?>

    you display the slug instead of the name.
    Put this code line in your theme where you want to get the language switcher.

    How to use custom language names then?
    I want to change to something other than the code

    I was looking for a solution to this issue and one of the first google results led to this page. My situation is a bit different as I want to use a standard Polylang widget in navigation menu, and calling <?php pll_the_languages(array(‘display_names_as’=>’slug’)); ?> does not solve this. So, I’ve studied the code and found a useful filter ‘pll_the_languages_args’. And I wrote this code to change the value from functions.php:

    /**
     * Display languages as slugs instead of full name.
     *
     * @param $args array Merged array of defaults and user settings for language selector
     *
     * @return array Modified array of arguments
     */
    function pss_language_as_slug( $args ) {
    
    	$args['display_names_as'] = 'slug';
    	return $args;
    
    }
    add_filter( 'pll_the_languages_args', 'pss_language_as_slug', 10, 1 );

    Hope this will help someone.

    @ihor Vornotov a gold one, than you!

    @marajo you’re welcome ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display language two-letter codes instead of language names’ is closed to new replies.