I am trying to get current language code via ICL_LANGUAGE_CODE in my plugin
but I can't , it's not defined , the result of this
echo "Code: ".ICL_LANGUAGE_CODE;
is
Code: ICL_LANGUAGE_NAME
When I trying the following
global $sitepress;
$current_language = $sitepress->get_current_language();
echo "Code:". $current_language ;
I get the blank screen.
I don't know in which way I can get it.
In the theme functions.php everything works fine. Thanks.
You can use WPML default filter to get the current language like this
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
the result will containe your current language code like : ar , en , fr ... etc
You can use the following code to get the current language code. I tried this in one of my plugin and its working.
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
echo ICL_LANGUAGE_CODE;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With