Skip Navigation

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

Problem:
The client wanted to place the WPML menu language switcher in the second last position of their menu, but the WPML settings only allow placement at the first or last position.
Solution:
We informed the client that WPML does not offer an option to insert the language switcher in the middle of the menu. However, we suggested using a shortcode for more flexibility or adding the switcher at the end of the menu and then re-adding the last item manually or with another menu (Menu 1 - Switcher - Menu 2).
We also provided a link to a resource that explains how to enable the use of shortcodes in header menu items: https://support.buddyboss.com/support/solutions/articles/72000599576-enable-the-use-of-shortcodes-in-header-menu-items
Additionally, we mentioned that if the client is comfortable with coding, they could use the wp_nav_menu_items hook to insert their last link after the switcher, as referenced here: https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/

Please note that this solution might be irrelevant due to being outdated or not applicable to your case. If so, we encourage you to open a new support ticket. We also highly 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 you need further assistance, please contact us in 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.

This topic contains 5 replies, has 3 voices.

Last updated by Nicolas V. 6 months, 4 weeks ago.

Assisted by: Nicolas V..

Author Posts
May 2, 2024 at 5:54 am #15585476

peterR-59

Hi there,

In WPML > Languages > Menu language switcher settings there are only options to have the menu language switcher in the first or last position.

If I wanted the menu language switcher in the second last position, is there a way to do this programmatically or would I need to move things around using CSS?

Cheers,
Peter Rees

Screenshot 2024-05-02 at 3.52.37 pm.png
May 2, 2024 at 6:23 am #15585550

Dražen Duvnjak
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hi Peter,

Thank you for contacting WPML support. While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with the first debugging steps and try to help with the issue quickly.

You will need to use language shortcode and add it to the part where you wish, as a menu item or via PHP code.

- https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/adding-language-switchers-using-php-and-shortcodes/

Regards,
Drazen

May 3, 2024 at 3:49 am #15589418

peterR-59

Hi Drazen,

Thanks for your reply.

However, my question is in regards to changing the order/position of the Menu language switcher (not implemented via shortcode).

Cheers,
Peter

May 3, 2024 at 2:27 pm #15591748

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi,

Unfortunately the two position offered are either before the menu (first item) or after the menu (last item). We don't have an option to insert it in the middle of your menu.

That's why Dražen recommended the use of a shortcode to offer you more flexibility. Another solution would be to add it at the end of the menu and remove the last item from the menu to add it again (either manually or with another menu: Menu 1 - Switcher - Menu 2).

Or look at how to add a shortcode inside a menu. A quick search on google brings this link: hidden link

Alternatively if you're comfortable with code, you could look at the wp_nav_menu_items hook to insert your last link after the switcher.
Ref: https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/

May 6, 2024 at 2:45 am #15594858

peterR-59

Hi Nicolas,

Thanks for your reply - I've updated functions.php to allow shortcodes in the menu and now have the language switcher displaying in the second-last position via shortcode.

I've selected the 'Dropdown' style in Custom Language Switchers settings but it doesn't display correctly as it appears to use a different markup (legacy markup?) to the Menu Language Switcher.

Is there any way to have the shortcode output the same markup as the Menu language switcher i.e. <ul class="dropdown-menu"> ?

Cheers,
Peter

Screenshot 2024-05-06 at 12.43.11 pm.png
Screenshot 2024-05-06 at 12.41.56 pm.png
May 6, 2024 at 12:43 pm #15597359

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi Peter,

Do you have an online version we could work on? It seems that the shortcode is inserted as a title which is wrong. I have activated a private field where you can share credentials.

In case you can't provide an online copy, I have created this sandbox site on our servers:
hidden link (one click login)

- I would need you to set up WPML + the WPML add-ons as you have them on your site (they are already installed) and then re-create a menu with the WPML shortcode.

Please don't install any other plugins that are not necessary to reproduce the issue.

May 7, 2024 at 12:09 am #15599467

peterR-59

Hi Nicolas,

I managed to append the last menu item using the wp_nav_menu_items hook as you suggested.

Thanks for your help.

Cheers,
Peter