Site logo

Archived topic

How to pass WPML parameters to the new Navigation Search button

5 replies · Started by Andrew on April 3, 2023

Viewing posts 1–6 of 6

We just enabled the new navigation search which is great (https://generatepress.com/a-new-navigation-search/). We are using WPML with language parameters however so our website adds lang=fr to the url when the user is in french. When a user is in french and they click on the magnifying glass it open up the dialogue in French (as expected) however the search results are sent to the english page as the lang=fr is removed from the URL. Is there anyway we can preserve that URL argument or some sort of hook we can connect to so we can add the url parameter with JS or PHP. I've reached out to WPML who asked me to connect with the GP forum. Thanks!

Hi there,

i must say, i have very little understanding of WPML or whether its getting in the way of these actions.
If i inspect the search form i see the opening tag:

<form role="search" method="get" class="search-modal-form" action="https://yourdomain.ca/?lang=fr">

And we can see the action="https://yourdomain.ca/?lang=fr" includes the lang query string.
So in theory that should be consider in the resulting search terms ie.

https://yourdomain.ca/?lang=fr&s=my_search_term

But it does not. Hmmm...

How does the core Search Block perform ? Does it keep the lang parameter in the search results?

To test this:

1. In Appearance > Elements -> Add New --> Block Element.
2. In the elements settings set the element type to Search Modal
3. Add a core Search Block to the content.
4. Set the Display Rules to the Entire site.

This will swap our search form for that block.

Hi David, thanks for the quick response. I don't actually see a "settings" option when adding a block. Can you please confirm this is what I'm looking for https://ibb.co/f2xyB57. I'll try out your solution to see if it works!

Thanks, Andrew

Ah, are you using Classic Editor plugin ?

Hi David, I was but I've disabled it and now everything shows up. I was also able to test and it turns out this solution does work! Thanks so much for sorting this out!

Ah, so it works with the core Search Block ?
If so ill do some tests as to why the themes search doesn't

This archived topic is closed to new replies.