Get language of current page in functions.php

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

Viewing 2 reply threads
  • Author
    Posts
    • #8579
      sweb1
      Participant

      Can I retrieve $lang of the current page in functions.php with an array for example like get_the_category()?

    • #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']
    • #8583
      sweb1
      Participant

      ok thank you!

Viewing 2 reply threads
  • The topic ‘Get language of current page in functions.php’ is closed to new replies.