Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is building a website and wants to display two different language switchers in different formats: one with language codes (EN | FR | DE) and another with full language names (English | French | German).
Solution:
We recommend using PHP actions to output custom language switchers in different formats. For the language codes, you can add a function to your theme's functions.php file and call it wherever you need it. Here's an example code snippet to display language codes:

function test_ls() {
    global $sitepress;
    $testls = $sitepress->get_ls_languages();

    foreach ( $testls as $lng ) {
        echo("<a href=" . $lng["url"] . ">" . strtoupper( $lng['code'] ) . "</a>");
        echo ("|");
    }
}

test_ls();

For full language names, you can use the existing options in WPML -> Languages to create one language switcher and style it as needed. For more information on customizing language switchers, you can refer to the following documentation:

Please note that custom coding is beyond the scope of our support. For further assistance, you can refer to the WPML hooks documentation:

If this solution doesn't look relevant, please open a new support ticket.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 3 voices.

Last updated by Waqas Bin Hasan 1 year, 7 months ago.

Assisted by: Waqas Bin Hasan.

Author Posts
September 12, 2023 at 9:49 am #14382317

thierryG-9

Hello, I'm building a website, that has two different language switchers. One is showing like: EN | FR | DE and another is like: English | French | German, what is the best way to achieve this, can you help me?

Best Regards

menu2.png
menu1.png
September 13, 2023 at 8:44 am #14388129

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

sure you can output custom language switcher via our PHP actions and to any position you want via WP hooks.

Example:

//WPML - Add a floating language switcher to the footer
 add_action('wp_footer', 'wpml_floating_language_switcher'); 
  
 function wpml_floating_language_switcher() { 
    echo '<div class="wpml-floating-language-switcher">';
        //PHP action to display the language switcher (see https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/#using-php-actions)
        do_action('wpml_add_language_selector');
    echo '</div>'; 
}

More info:

- https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/custom-language-switcher/
- https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/adding-language-switchers-using-php-and-shortcodes/

Regards,
Drazen

September 13, 2023 at 10:44 am #14389321

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting the support. I am assigned this ticket.

Please let me know if the above mentioned solution works for you.

Regards.

September 14, 2023 at 6:51 pm #14399345

thierryG-9

Hello, I know that I can output the custom language switcher via PHP actions. My problem is: in one place want the languages to be: EN | DE | FR and in the another place to be: English | German | French, do you know what I mean? I sent the screenshots to be as clear as possible.

Thanks for the help,

Best Regards

September 15, 2023 at 7:10 am #14400855

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Maybe the one place can be the footer language switcher where you can customize the LS to be like that and then customize the "Other language switcher" to be like the other and include it via code.

For example, the following code 'll output a kind of EN | DE | SK (as per my configured languages - see attached):

function test_ls() {
    global $sitepress;
    $testls = $sitepress->get_ls_languages();
    foreach ( $testls as $lng ) {
        echo( "<a href=" . $lng["url"] . ">" . strtoupper( $lng['code'] ) . "</a>" );
        echo ("|");
    }
}

test_ls();

You can place that function in your theme's functions.php file and use test_ls() wherever you need it to display. You can also create a shortcode (hidden link) of that for the ease of use in your templates or content places.

You may also style it as needed.

In short, the whole idea is that, you can create and use one language switcher from existing options in WPML -> Languages, and code one to suite your other custom need.

Please note that custom coding is out of scope of this forum. However, you can check following WPML hooks for more information:
- https://wpml.org/wpml-hook/wpml_post_language_details/
- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

image.png