Michael
Michael

Reputation: 31

How to determine language with twig and wmpl

I am trying to determine the language in a wordpress / twig website. I tried the following in twig :

{{ wpml_current_lang }} 

But that doesnt seem to work. Any idea's or suggestions ?

Upvotes: 3

Views: 2191

Answers (2)

MrVanilla
MrVanilla

Reputation: 367

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 %}

Upvotes: 1

Hans Dash
Hans Dash

Reputation: 761

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).

Upvotes: 0

Related Questions