icl_ls_languages
- Type
- filter
- Category
- Miscellaneous
- 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.
Arguments
- $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.
Frenchwhen 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.
- active:
1if the language is currently active and0otherwise.
- default_locale: The language locale. i.e.
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;
}
Related hooks
wpml_sync_custom_field_copied_value, wpml_ls_enable_ajax_navigation, wpml_element_type, wpml_setting, wpml_sub_setting, wpml_exclude_post_from_auto_translate, wpml_forms_config_ninja-forms, wpml_forms_config_wpforms, wpml_tf_feedback_open_link, wpml_translatable_user_meta_fields