Search code examples
phpwordpresspolylang

How to get the active language in WordPress Polylang


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?


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.