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'];
The topic ‘[Closed] WP Nav Menus’ is closed to new replies.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.