Tell us what you are trying to do?
I'd like the navigation menus to programmatically show the language variant of a link, otherwise fall back to the default language.
Is there any documentation that you are following?
I can't find any.
Is there a similar example that we can see? hidden link
What is the link to your site? hidden link
For context, the client only wants about 20% of the website translated into different languages.
Thank you for contacting the support forum.
Before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.
The current behavior of WPML is as soon as you translate the content the translated links are shown in the menu and untranslated content is skipped. This is what happening currently on the site.
The other option is to display the original menu as it is without translating them at all. This is not an official feature but there is a workaround. You can add this code to the theme's functions.php
$locations_to_omit = ['primary']; //Append menu locations here. e.g. ['primary', 'footer']
add_filter('wp_nav_menu_args', function ($args) use ($locations_to_omit) {
if (isset($args['theme_location']) && in_array($args['theme_location'], $locations_to_omit)) {
$current_lang = apply_filters( 'wpml_current_language', null );
do_action('wpml_switch_language', apply_filters( 'wpml_default_language', null ));
add_filter('wp_nav_menu', function ($nav_menu) use ($current_lang){
do_action('wpml_switch_language', $current_lang);
return $nav_menu;
}, 99);
}
return $args;
}, 1);
In the code you need to add the menu location name here $locations_to_omit = ['primary'];