I search for a variable that outputs the currently used language of the polylang plugin. Something like:
if($curlang == "en") {
...
}
I search for a variable that outputs the currently used language of the polylang plugin. Something like:
if($curlang == "en") {
...
}
You must be logged in to post a comment.
We can use the
get_locale
function:To show current language, you can use:
Plain and simple
Simple:
This plugin is documented rather good in https://polylang.wordpress.com/documentation.
Switching post language
The developers documentation states the following logic as a means to generate URL’s for different translations of the same post
If you want more influence on what is rendered, inspet
pll_the_languages
function and copy it’s behaviour to your own output implementationSwitching site language
As you want buttons to switch language, this page: https://polylang.wordpress.com/documentation/frequently-asked-questions/the-language-switcher/ will give you the required info.
An implementation example:
Then style with CSS to create buttons, flags or whatever you want.
It is also possible to use a widget for this, provided by te plugin
Getting current language
All plugins functions are explained here: https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
In this case use:
I use something like this: