Reply To: Get language of current page in functions.php

Home Forums WordPress Plugins Language Switcher Get language of current page in functions.php Reply To: Get language of current page in functions.php

#8582
Rafasashi
Keymaster

Technically yes.

Assuming you have a $post_id you can do:

$lang = Language_Switcher::instance()->get_post_language($post_id);

For a term it is:

$lang = Language_Switcher::instance()->get_term_language($term_id);

Either way you should get something like:

array(2) {
  ["urls"]=>
  array(1) {
    ["en"]=>
    bool(false)
  }
  ["main"]=>
  string(2) "en"
}

To retrieve the language use:

$lang['main']