php - How to get the active language in WordPress Polylang
Get the solution ↓↓↓I have setup Polylang on my WP and created pages for those 2 different languages (EN, GR). But I want to override a plugin and present some strings in greek if the selected Frontpage language is in Greek. I have tested with get_locale() and and get_bloginfo('language'), but both of them return the locale of the Administrator side which is en_US.
I have also tried with $_SERVER['REQUEST_URI'] of PHP_INFO, because when in EN the address bar contain the /en/ part, but I don't get the correct addres, rather a json request address created for the current request.
How I can get the frontend user language?
Answer
Solution:
I have finally succeeded to get the current language with
isset($_COOKIE['pll_language']) ? $_COOKIE['pll_language'] : false;
and it returns "en" or "el" depending the active language.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: installation failed, reverting ./composer.json and ./composer.lock to their original content
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.