Skip Navigation
availability:

WPML Version: 3.2.0

description:

Allows you to filter the displayed languages of the language switcher. You can use this filter when you need to add additional URLs or flags to an existing language switcher.

type:
filter
category:
Miscellaneous
parameters:
  • $languages (array) Collection of active languages to display in the language switcher. Each language is an array of:
    • default_locale: The language locale. i.e. fr_FR
    • language_code: The language code. i.e. fr
    • native_name: Name of the language in its own language. i.e. Français
    • translated_name: Name of the language in the current active language. i.e. French when English is the current active language.
    • url: The URL to the language of the current page. This is used for the link in the language switcher.
    • active1 if the language is currently active and 0 otherwise.
hook example usage:

Example

The following example changes the URL of a French link to a custom external URL

add_filter( 'icl_ls_languages', 'my_change_french_url_to_custom_external_site' );
function my_change_french_url_to_custom_external_site( $languages ) {
    foreach( $languages as &$language ) {
        if( $language['default_locale'] === 'fr_FR' ) {
            $language['url'] = 'https://my-custom-external-url.com';
            break;
        }
    }

    return $languages;
}