Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active January 13, 2023 10:46
Show Gist options
  • Save vielhuber/196b512d6e034e25bc40f6f355d0bedd to your computer and use it in GitHub Desktop.
Save vielhuber/196b512d6e034e25bc40f6f355d0bedd 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