Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPML |Get the current ICL_LANGUAGE_CODE with JS

I tried to retrieve the current ICL language with this code but it doesn't work.

var getLangCode = '<?php echo ICL_LANGUAGE_CODE; ?>';

alert(getLangCode);

Do you know how can I get the current language code with javascript ?

Thanks in advance !

enter image description here

like image 398
colapsnux Avatar asked Oct 18 '25 10:10

colapsnux


2 Answers

You just need to place the quotes in the right places.

Remove quotes before <?php and after ?> and surround the PHP constant with double quotes.

var getLangCode = <?php echo '"' . ICL_LANGUAGE_CODE . '"' ; ?> ;

alert(getLangCode);
like image 59
Enzo Avatar answered Oct 21 '25 01:10

Enzo


The better way to do this is:

   var lang = document.documentElement.lang;
like image 29
Joel Newcomer Avatar answered Oct 20 '25 23:10

Joel Newcomer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!