WPML & TWIG | Determinate which language is active
This time i have to update a wordpress website developed with TWIG and that use WPML.
Customer ask me for a conditional tag based on active language.
Normally ( in php ) i use the wpml function
<?php
if (ICL_LANGUAGE_CODE == "fr") {
    //show content in French
} elseif (ICL_LANGUAGE_CODE == "de") {
    //show content in German
} else {
    //show the default content in English
}
?>
But with TWIG i can’t use this code.
So “googling” i found that we can use
{{site.language}} // it give back the active language in twig
So, now, i can re arrange the WPML function for use it with TWIG:
{% if site.language == 'fr-FR' %}
  //show content in French
{% else if site.language == 'de-DE'%}
  //show content in German
{% else %}
  //show the default content in English
{% endif %}
From now you can have a “conditional” based on active language in TWIG.
That’s All
 
					