Skip to content

Instantly share code, notes, and snippets.

@banarsiamin
Forked from vielhuber/script.php
Created June 9, 2021 12:35
Show Gist options
  • Save banarsiamin/48c6b6ab5b46ed4b0a8dab098b0c7164 to your computer and use it in GitHub Desktop.
Save banarsiamin/48c6b6ab5b46ed4b0a8dab098b0c7164 to your computer and use it in GitHub Desktop.
get current language (with locale) #wpml #wordpress
<?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