skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. They provide a function for that : pll_current_language().

    See their documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search