Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is redesigning a website and wants the English menu to display in its entirety for all languages without manually creating the menu in each language. This is to avoid updating 10+ menus every time a page is added to the English menu.
Solution:
Currently, WPML does not support automatic duplication of menus across different languages. The client has two options:
1. Manually duplicate the menus by going to Appearance > Menus, clicking on the "+" sign to add menus in secondary languages, and inserting the English links and labels.
2. Implement a custom code solution. The client can try editing the provided code to fit their context or consult with professional contractors for assistance. The code provided earlier should be added to the functions.php file, ensuring a backup is made first due to potential risks:

$locations_to_omit = ['header']; //Append menu locations here. e.g. ['primary', 'footer']<br />add_filter('wp_nav_menu_args', function ($args) use ($locations_to_omit) {<br />    if (isset($args['theme_location']) && in_array($args['theme_location'], $locations_to_omit)) {<br />        $current_lang = apply_filters( 'wpml_current_language', null );<br />        do_action('wpml_switch_language', apply_filters( 'wpml_default_language', null ));<br />        <br />        add_filter('wp_nav_menu', function ($nav_menu) use ($current_lang){<br />            do_action('wpml_switch_language', $current_lang);<br />            return $nav_menu;<br />        }, 99);<br />    }<br />    <br />    return $args;<br />}, 1);

If these solutions do not resolve the issue or if the solution becomes outdated, we recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Lucas Vidal de Andrade 2 weeks, 3 days ago.

Assisted by: Lucas Vidal de Andrade.

Author Posts
October 30, 2024 at 2:05 pm #16347620

Todd

Background of the issue:
I am redesigning a website that will be 99% English, with a single page for each of the languages in the menu switcher. I want the English menu to display in its entirety for all languages without manually creating the menu in each language, as this would require updating 10+ menus every time a page is added to the English menu.

Symptoms:
I found a few older tickets but they were confusing and hard to follow.

Questions:
How can I display the English menu for all languages without manually creating it in each language?

October 30, 2024 at 7:39 pm #16348984

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

I'm still checking. I'll be back once I have new information. Thank you for your patience.

October 31, 2024 at 2:33 pm #16352215

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

I tested the solution in a testing environment, and it worked like a charm. Note the in the first line of the code, you have to insert the menu location:

$locations_to_omit = ['header']; //Append menu locations here. e.g. ['primary', 'footer']

Based on what you shared, I put the location 'header'. Please check carefully the location of the menu you inserted, to see if it matches the variable that must be inserted there. It's the only part of the code that can/must be changed.

Make sure to have a full website backup and that this code is inserted at the end of your active theme's functions.php file.

Let me know how it goes.

October 31, 2024 at 5:01 pm #16352835

Todd

Hi Lucas

I'm sharing two screenshots.

Dark is the functions.php and the code I added as you provided.

Light is header.php for the theme I'm using (Hello Elementor). If I'm reading and understanding it correctly, the location is 'header.'

So, what can be the problem now?

Maybe I set something incorrectly in WPML settings? Would you like admin access to check?

Thanks again!
Todd

Screenshot 2024-10-31 at 18.57.22.png
Screenshot 2024-10-31 at 18.58.28.png
November 1, 2024 at 3:31 pm #16355493

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

I'm getting a second opinion with my colleagues. Unfortunately, this solution is outside the scope of our support. The correct way to proceed here would be to create a feature request. We cannot create custom code for customers. I sent you the code because I found it in an old internal ticket and thought it might be useful. If it's not working, you must correct it yourself, or ask us for the feature request I mentioned.

I'll see what's possible and will get back to you, ok?

November 1, 2024 at 5:32 pm #16355763

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

I talked to my other colleagues and in this situation we can only offer the two options:

1. Duplicate the menus manually. To do that go to Appearance > Menus, click on the "+" sign to add menus in secondary languages, and insert the EN links and labels.
2. Via code. To do that, you can try editing the code we sent, so it works in your context, or check our professional contractors service, here:
https://wpml.org/contractors/

I apologize for not being able to find a quick solution. Since a workaround involves custom code and is not part of the set of features, we cannot help further. I'll check if we have some ongoing feature request, to add this ticket as reference.

Thank you for understanding.