Last active
November 1, 2023 10:21
-
-
Save jhtjards/c06eda3db0216b777ce20e3363716f26 to your computer and use it in GitHub Desktop.
The WPML constant ICL_LANGUAGE_NAME and others are deprecated in WPML v4.6.7. This is a replacement template function for that and more.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'wpml_get_current_language_name' ) ) : | |
/** | |
* Returns current active site language array. | |
* If the optional $arg is set, only the corresponding value is returned. | |
* | |
* $arg can be one of: | |
* code, id, native_name, major, active, default_locale, | |
* encode_url, tag, translated_name, url, country_flag_url, language_code | |
*/ | |
function wpml_get_current_language( $arg = NULL ){ | |
$wpml_active_languages = apply_filters( 'wpml_active_languages', NULL, NULL ); | |
if ( !is_array( $wpml_active_languages ) ) { | |
return null; | |
} | |
foreach ($wpml_active_languages as $key => $language) { | |
if ( isset($language['active']) && $language['active'] == 1 ) { | |
//return language array | |
if(!$arg){ | |
return $language; | |
} | |
//return only selected language value | |
//one of ["code"], ["id"], ["native_name"], ["major"], ["active"], ["default_locale"], ["encode_url"], ["tag"], ["translated_name"], ["url"], ["country_flag_url"], ["language_code"] | |
if( $arg && isset($language[$arg]) ){ | |
return $language[$arg]; | |
} | |
} | |
} | |
return null; //No active language | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment