• Anonymous User 11986954

    (@anonymized-11986954)


    I’m developing an admin component where I need to know which language is currently selected *in the admin area*.

    I can’t find anything in the dev docs, I tried pll_current_language but it does not seem to work in admin. Anything else I can try?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Martin H

    (@martinlefarweb)

    I had the same issue recently.

    pll_current_language() doesn’t seem to work in the backend of WordPress but you can use get_bloginfo(‘language’) or get_locale() (didn’t try the last one). It will return somehting like this : ‘en-GB’ or ‘en_GB’

    https://polylang.pro/doc/developpers-how-to/#language-load

    Than you can use strstr function to strip out the end of the string : strstr(get_bloginfo(‘language’), ‘-‘, true)

    Maybe Polylang can confirm this work around.

    • This reply was modified 4 years, 10 months ago by Martin H.
    Martin H

    (@martinlefarweb)

    Nope.
    Get_bloginfo(‘language’) is returning the main language of the website.

    You can use this instead:

    global $polylang;
    $p_locale = $polylang->pref_lang->slug;

    If not language are selected it will return the main language.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get current language in admin’ is closed to new replies.