• 0

wordpress: adding a content (language) switcher to the menu


Question

dear community hello dear experts,

 

 


I am developing a site in Wordpress. I am using the twentyseventeen-theme. i would like language-[content-] switcher in mega menu – without any ml-system - because i do not need ml-things. While customizing the the theme according to my website needs, i found that the theme only supports one menu. I want to add another menu.  

 

at the moment the site has  

 

– Max-Mega-Menü
– etc. etx

 

in the menu the estimated textamount has got max 2000 words – in five languages: german, english; french, spanish, italien
note:  the texts are allready translated – no need to do a runtime translation or something similar.  I have a defined text amount where which is allready translated.

what is aimed: i want to add all those texts in to the max-mega-menu:
idea: can i do this with a added (language-[content] )switcher in the mega menu

guess: i guess that this is possible – without using a multilang system eg. like:

 

-WPML
-Polylang
-Weglot
-TranslatePress

 

again; since i only have a little amount of text which is allready translated completely i guess that i do not need a multilang system.  I guess that a  (language- [content])-switcher will be sufficient to arrrange this.


see the example:

 -----------------------
 | switcher of  content |
 -----------------------
     |
     |
    /|\
 ---------         ---------          ----------       ---------           ---------
 |german  |-------< |  engl. |>-------|french.  |>------|span.  |>---------|italien.|
 ---------         ---------          ----------       ---------           ---------
    \|/
     |
     |
 ------------
 |Lorem ipsum|     etc. eng.         etc. french       etc.spanish          etc.italien
 ------------
    \|/
     |
     |
 ---------
 | blabla |
 ---------


 

 furthermore:  to show the needs in another picture i add a second - here we see more things ...
see the structure of the page...


    language-switcher: de :: fr :: it ::es :: pt :: eng :: ...--+
    |                                                           |
    +-----------------------------------------------------------+
    +--------------------------------------------------------------------------------------------------------------+
    |                                                                                                              |
    |   +-------------------+ +------------------+ +----------------------------------+ +-------------------+      |
    |   |                   | |                  | |                ||                | |                   |      |
    |   |        Item 1     | |        Item 2    | |      Item 3    ||     Item 4     | |        Item 5     |      |
    |   |                   | |                  | |                ||                | |                   |      |
    |   |                   | |                  | |                ||                | |                   |      |
    |   |                   | |                  | |                ||                | |                   |      |
    |   +-------------------+ +------------------+ +----------------------------------+ +-------------------+      |
    |                                                                                                              |
    |                                                                                                              |
    |                                                                                                              |
    |                                                                                                              |
    |                                                                                                              |
    |                                                                                                              |
    |                                                                                                              |
    +--------------------------------------------------------------------------------------------------------------+
    

so i think that ,,,,I want to add another menu.... for the different languages i have - 6 different languages: .... subsequently i should add six menus in the code below...

approach: could i do it like so:</strong> Add the following code to the functions.php file. The 2 menus are the “Primary”, and “Secondary” menus.

//Register Navigations
add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
   register_nav_menus(
        array(
            'primary-menu' => __( 'Primary Menu' ),
            'secondary-menu' => __( 'Secondary Menu' )
        )
    );
}

 

conclusio: so i think that ,,,,i have to add alot - for the different languages i have - 6 different languages: .... subsequently i should add six menus in the code above...

well i have mused alot bout the code: To add them to my site i should have to add the following to the WordPress template files (most likely my header.php and footer.php files).


<?php wp_nav_menu (array('theme_location' => 'primary-menu','menu_class' => 'nav'));?>
<?php wp_nav_menu (array('theme_location' => 'secondary-menu','menu_class' => 'nav'));?>
    

 
and so forth and so forth... untill i reach the six different languages..


Well - what do you think!? does this fit the needs!?

What do you think?  Love to hear from you.

1 answer to this question

Recommended Posts

  • 0

hi there  - good day  dear friends,

 

i have tried to find out more information on this issue:  hile i have tried to find information about how to add a language-switcher to the menu of wordpress i thougth it could go like so:

In Appearance->Menues, we have the checkbox option for the following:

  Quote

 

“Add one of this for each of your languages”.

 

Expand  

 

the question is: what does it do actually?

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

guess:  well i think it just creates and adds to menu a certain custom link with the  name “language” and a empty url.


This custom link will then be replaced by actual language link in runtime. So if the site has got 3 different languages, we need 3 custom links like this. e can use the for all languages via a global variable: the so called

 global $sublanguage:

 

this will finally lead us to the following:
 

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 above mentioned ideas were inspired by this thread:  https://wordpress.org/support/topic/add-language-switcher-to-menu/

note: i will do some checks to see if this fits for me...

 

 

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Windows 11 is getting a useful new audio feature by Taras Buria Photo: phamtu1509 Windows 11, in its current form, does not offer a quick and easy way to play audio over more than one device. If you have a bunch of audio devices connected and you want to play music on all of them, you have to tinker with third-party software to make it work. Apparently, Microsoft wants to change that with a new feature coming soon to Windows 11. @phantomofearth, the ever-giving source of Windows insights, discovered that the latest Windows 11 preview builds have a hidden toggle in quick settings that lets you share audio to multiple devices with just a few clicks. All it takes is clicking "Shared Audio" in the control center, selecting two or more available devices, and pressing "Share." As usual, there are no official announcements yet, so details about this feature remain unknown. Still, you can probably expect the new shared audio feature to make it to a Windows 11 preview build in the near future. In other Windows Insider news, Microsoft recently revealed that one of the recent taskbar changes was pulled from the operating system due to negative feedback. The company experimented with a simplified taskbar tray area, but later decided to nuke it because people did not like it. Still, there are plenty of other features coming soon to Windows 11. Check out our recent top 10 list here. Hopefully, all of them will make it to the Stable channel soon.
    • Chinese? It sounds extremely dangerous. I’ll reconsider buying a Meta Quest 3.
    • - What's your salary? Is it more than $100k a year? - Nah, it's $100 mil a year.
    • Compared to my ear buds which are the size of a matchbox, cover a much broader frequency range, and work everywhere without setup? Yeah, still not buying this as a replacement.
    • Meta's Superintelligence team staffed by 50% Chinese talent, 40% ex-OpenAI by Hamid Ganji Mark Zuckerberg's latest big bet at Meta involves building a team of the best AI superstars in the market to lead the so-called Superintelligence Labs. The goal of this team is to develop AI models that will ultimately lead to Artificial General Intelligence (AGI). AGI refers to an AI model with capabilities comparable to, or even beyond, those of the human brain. Achieving human-level cognitive abilities with an AI model requires substantial investments, as well as hiring the best talent to build such a system. That's why Meta is throwing hundreds of millions of dollars at AI researchers from OpenAI, Apple, and other companies to recruit them for its Superintelligence team. A user on X has now shared a spreadsheet that provides us with some unique insights into Meta's Superintelligence team and the origins of its 44 employees. The leaker claims this information comes from an anonymous Meta employee. The listing claims that 50 percent of the staff at the Superintelligence team are from China, which demonstrates the significant role of Chinese or Chinese-origin researchers in Met's AI efforts. Additionally, 75 percent of these staff hold PhDs, and 70 percent of them work as researchers. Interestingly, 40 percent of the staff are ex-OpenAI employees whom Mark Zuckerberg poached from the maker of ChatGPT. Additionally, 20 percent of Meta's Superintelligence team members come from Google DeepMind, and another 15 percent come from Scale AI, a startup that Meta recently acquired in a $15 billion deal. Another interesting point is that 75 percent of the Superintelligence team are first-generation immigrants. The leaker claims that each of these employees is now earning between $10 million and $100 million per year, although Meta still needs to confirm these substantial figures. However, it has already been reported that Meta is offering up to $100 million in signup bonuses to poach the best AI talent from OpenAI and other rivals. The revelation that half of Meta's Superintelligence team consists of Chinese nationals could trigger concerns within the Trump administration and Congress.
  • Recent Achievements

    • First Post
      nobody9 earned a badge
      First Post
    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      ATLien_0
      207
    3. 3
      Michael Scrip
      206
    4. 4
      Xenon
      138
    5. 5
      +FloatingFatMan
      112
  • Tell a friend

    Love Neowin? Tell a friend!