Skip Navigation

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

Problem:
If you're experiencing an issue where your menu falls back to its default language when navigating in a language that doesn't have a menu translation, and each menu item is using its original post_title instead of the "Navigation Label" defined in the menu builder, we understand your concern.

Solution:
We have identified that this behavior is not a bug but a feature since WPML version 4.5. When a menu is not translated, WPML automatically translates the menu items to the translated post/page titles and links. However, if you prefer to display the original menu with the navigation labels as set in the menu builder, we have a workaround. You can prevent the automatic menu translation by WPML using the code provided in our documentation:
Prevent automatic menu translation by WPML when menu not translated in other languages
By implementing this code, you will disable the "On The Fly translation" of the menu, allowing the original menu to display.

Please note that this solution might be irrelevant if it's outdated or not applicable to your case. If the workaround does not resolve your issue, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please do not hesitate to open a new support ticket with us.

In case further help is needed, you can reach out to us on the 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 Mihai Apetrei 10 months, 1 week ago.

Assisted by: Mihai Apetrei.

Author Posts
January 16, 2024 at 3:06 pm #15190813

davidP-133

There is a bug on classes/inc/wp-nav-menus/TranslateMenu.php on line 51 function translateItem(), when a menu fallbacks to its default language when navigating on a language that doesn't have that menu translation each menu item is using its original post_title and not the "Navigation Label" defined on the menu builder. Could that be added to the next changelog

January 16, 2024 at 3:22 pm #15190931

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

This is the ticket that we converted our live chat to.

I will be waiting for an update from you when the issue is replicated.

Thank you very much once again!

Mihai

January 16, 2024 at 3:24 pm #15190933

davidP-133

The issue is replicated, you can see here that the menu item is not picking up the "Navigation label" set on the menu builder on the french version of the site hidden link

To fix this I did the next changes

/**
* @param \WP_Post $item Menu item - post object.
*
* @return \WP_Post
*/
public static function translateItem( $item ) {
if ( 'post_type' === $item->type ) {
$translatedId = self::getTranslatedId( $item, true );
$post = Post::get( $translatedId );
if ( ! $post instanceof \WP_Post ) {
return $item;
}
foreach ( get_object_vars( $post ) as $key => $value ) {
// We won't send the translated ID, since it affects front-end styles negatively.
if ( ! in_array( $key, [ 'menu_order', 'post_type', 'ID' ] ) ) {
$item->$key = $value;
}
}
$item->object_id = (string) $translatedId;

if(empty($item->title)){
$item->title = $item->post_title;
}

}

return $item;
}

January 16, 2024 at 10:52 pm #15192327

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Thank you!

I will escalate this forward.

Mihai

January 23, 2024 at 2:57 pm #15217775

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

I am updating the status of this ticket to "Escalated to WPML developers team".

Mihai

January 27, 2024 at 10:18 pm #15233408

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

I am back with updates.

My colleagues informed me that this is not a bug, it is a feature of WPML since version 4.5.

When the menu is not translated, WPML automatically translates the menu items to the translated posts/page titles and links. But since we set the pages to display as translated, the menu links are adjusted but not the title.

If we use a navigation label instead of post/page title, this feature will break and it will always display the untranslated navigation label even if the post/page is translated.

We have a workaround for this:
hidden link

If you do not wish to translate the menu and want to display the original menu, the above code can be used. This will turn off the "On The Fly translation" of the menu.

We added the above code on the sandbox testing site and it works:
hidden link

I hope that you will find this information helpful.

Mihai