Support » Plugin: Sublanguage » Add language switcher to menu

  • Hi.
    I have tried to find information about how to add a language switcher to the menu.

    In Appearance->Menues, what is this checkbox option for? “Add one of this for each of your languages”. I don’t understand what it does?

    Is it possible to get all languages via a global variable?

Viewing 1 replies (of 1 total)
  • Plugin Author maximeschoeni

    (@maximeschoeni)

    Hello,

    Actually it will just create and add to menu a custom link with name “language” and empty url. This custom link will be replaced by actual language link in runtime. So if your site have 3 languages, you need 3 custom links like this.

    Is it possible to get all languages via a global variable?

    Yes, the global $sublanguage:

    
    global $sublanguage;
    $languages = $sublanguage->get_languages(); // return an array of WP_Post objects
    foreach ($languages as $language) {
      echo $language->post_title; // -> title of language (Ex: "English")
      echo $language->post_name; // -> slug of language (Ex: "en")
      echo $language->post_content; // -> locale code of language (Ex: "en_US")
      echo $sublanguage->get_translation_link($language); // -> language url for current page
    }
    
    • This reply was modified 9 months, 3 weeks ago by maximeschoeni.
Viewing 1 replies (of 1 total)
  • The topic ‘Add language switcher to menu’ is closed to new replies.