- availability:
-
WPML Version: 3.2
- description:
-
Checks if the native name of a language and the translated name of the same language are different. If so, it returns them both. Otherwise, it returns only one.
This filter is usually used in custom language switchers. - type:
- filter
- category:
- Site-Wide Language Information
- parameters:
-
apply_filters( 'wpml_display_language_names', mixed $empty_value, string $native_name, string|bool $translated_name, bool $lang_native_hidden, bool $lang_translated_hidden )
- $empty_value
- (mixed) (Required) This is normally the value the filter will be modifying. We are not filtering anything here so set this to NULL. This for the filter function to actually receive the full argument list
- $native_name
- (string) (Required) The language native name
- $translated_name
- (string|bool) (Required) The language translated name Defaults to FALSE
- $lang_native_hidden
- (bool) (Optional) Default is FALSE 0|false or 1|true Whether to hide the language native name or not
- $lang_translated_hidden
- (bool) (Optional) Default is FALSE 0|false or 1|true Whether to hide the language translated name or not
- hook example usage:
-
Example
function my_footer_languages_list(){ $languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0&orderby=code' ); if( !empty( $languages ) ){ echo '<div id="footer_language_list"><ul>'; foreach( $languages as $l ){ echo '<li>'; if( $l['country_flag_url'] ){ if( !$l['active'] ) echo '<a href="'.$l['url'].'">'; echo '<img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" />'; if( !$l['active'] ) echo '</a>'; } if(!$l['active']) echo '<a href="'.$l['url'].'">'; echo apply_filters( 'wpml_display_language_names', NULL, $l['native_name'], $l['translated_name'] ); if( !$l['active'] ) echo '</a>'; echo '</li>'; } echo '</ul></div>'; } }
The example function above does the following:
- If there are any languages, it creates a DIV and starts an unordered list
- Then it loops through each of the languages and adds it as a list item.
If the language is not the active language, it adds a link to the translated page for that language - It then adds the language flag
- Finally, it adds both the native and translated language names if they’re different