-
-
Save banarsiamin/48c6b6ab5b46ed4b0a8dab098b0c7164 to your computer and use it in GitHub Desktop.
get current language (with locale) #wpml #wordpress
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 | |
// returns 'en' | |
apply_filters( 'wpml_current_language', NULL ); | |
// returns 'en' | |
global $sitepress; | |
$lang = $sitepress->get_current_language(); | |
// returns 'en' (deprecated, does also not work when you switched languages programmatically) | |
if(defined('ICL_LANGUAGE_CODE')) { | |
echo ICL_LANGUAGE_CODE; | |
} | |
// returns 'en_US' | |
$lng = ''; | |
foreach(apply_filters( 'wpml_active_languages', null ) as $languages__value) { | |
if ($languages__value['active']) { $lng = $languages__value['default_locale']; break; } | |
} | |
echo $lng; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment