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 !
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);
The better way to do this is:
var lang = document.documentElement.lang;
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