How to determine language with twig and wmpl How to determine language with twig and wmpl wordpress wordpress

How to determine language with twig and wmpl


I used this method to get a two letter language code: in index.php

$context['lang'] = strtolower( substr( get_locale(), 0, 2 ) );

then in the template.twig I could access lang like this:

 <!--language: {{lang}}-->  

Of course, after I did this, I found out you could also use a build in constant, like described here: https://github.com/timber/timber/wiki/TimberSite

{{site.language}} 

will give you the same as bloginfo('language') (this I did not test).


This returns the language code as a string

{{ site.language }}

If you want to use logic you can do something like this

{% if site.language == 'en_GB' %}do stuff{% else % }do other stuff{% endif %}