- This topic has 15 replies, 2 voices, and was last updated 1 year, 11 months ago by Leo.
-
AuthorPosts
-
May 7, 2022 at 11:55 pm #2213013Leo
I have my site in three languages with Polylang. Catalan is the default language, while Spanish and English are the secondary languages.
I’ve customized the 404 error page using a plugin and made three versions of it -one for each language. I also added a search box block on each error page.
There are no issues with that search box in the default language. The problem occurs when using the search box in Spanish or English: in those cases, the system seeks matches in Catalan instead of the current language.
For example, if you search the word “balloon” from the error page in English, you will get no results, despite some pages matching that word. Besides, the system jumps to the Catalan version of the site when displaying the no-matches notification.
Interestingly, this problem doesn’t happen when using the magnifying glass in the menu.
May 8, 2022 at 3:06 am #2213089DavidStaffCustomer SupportHi there,
so the Search form in the 404 template has the same
action
attribute for all languages ie. the main domain not the subfolder. So all searches will be the same.Instead of using the Plugin to create the different 404s – have you tried using the Block Element – Content Template ?
May 10, 2022 at 8:06 am #2215407LeoThank you, David. I have created the error pages with Elements and got rid of the plugin. Elements are so powerful and helpful!
However, the problem with the language box remains the same.
The problem occurs when using the search box in Spanish or English: in those cases, the system seeks matches in Catalan instead of the current language.
For example, if you search the word “balloon” from the error page in English, you will get no results, despite some pages matching that word. Besides, the system jumps to the Catalan version of the site when displaying the no-matches notification.
Interestingly, this problem doesn’t happen when using the magnifying glass in the menu.
May 12, 2022 at 10:51 pm #2218146LeoHi guys,
I’m still struggling to change the language of the search box results.
Results show up in Catalan, even if the search comes from the English or Spanish version of the website.
However, searches using the magnifying glass in the menu are just fine. They match the language.
If you can point me on how to fix this problem, I’ll appreciate it.
Thank you! 🙂
May 13, 2022 at 4:11 am #2218328DavidStaffCustomer SupportSorry we missed your last reply.
So the core Search Block doesn’t respect the current URL.You could try adding this PHP Snippet to create your own search form shortcode:
add_shortcode( 'search_form', function() { ob_start(); ?> <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> <label> <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span> <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" /> </label> <input type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" /> </form> <?php return ob_get_clean(); } );
Then instead of add the Search Block add shortcode:
[search_form]
May 14, 2022 at 11:31 pm #2219890LeoThank you for your help, David. I followed your suggestion, but unfortunately the problem keeps the same.
May 15, 2022 at 4:17 am #2220001DavidStaffCustomer SupportCan you clear any caches and try again ?
May 15, 2022 at 12:11 pm #2220514LeoI cleared the website cache as well as my browser cache, but the problem persists.
May 16, 2022 at 4:14 am #2220949DavidStaffCustomer SupportOk i am sure there is probably a much easier way to do this, and you may want to ask Polylang for their input. But in the meantime, try updating the Shortcode snippet to:
add_shortcode( 'search_form', function() { ob_start(); ?> <form role="search" method="get" class="search-form" action="<?php echo home_url() . '/' . pll_current_language(); ?>"> <label> <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span> <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" /> </label> <input type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" /> </form> <?php return ob_get_clean(); } );
The change is to just this line:
<form role="search" method="get" class="search-form" action="<?php echo home_url() . '/' . pll_current_language(); ?>">
May 16, 2022 at 2:15 pm #2221716LeoThank you, David, it’s fantastic! I’m very grateful. 🙂
A similar thread has been open in the Poylang forum for more than two years and a half. A few people seem to suffer this issue, and the plugin authors haven’t yet fixed it. I posted the workaround you gave me just in case it could help anybody else.
Just one more thing. The search form displays the word “Search,” which is okay in English, but in Catalan and Spanish, it should say “Cerca” and “Busca.”
I got the idea to create three snippets with three different shortcodes, one for each language, but maybe there is an easier way of doing this. What do you recommend?
May 17, 2022 at 1:07 am #2221997DavidStaffCustomer SupportSo this line:
placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>"
you should be able to change it to this:
placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder', 'generatepress' ) ?>"
that will include the GP text domain for translation.
May 17, 2022 at 10:54 pm #2223230LeoThe text “Search …” doesn’t show up in Polylang’s string translations. I tried changing
'generatepress'
to'gp-premium'
, but it isn’t working either.May 18, 2022 at 3:17 am #2223420DavidStaffCustomer SupportYou can change the placeholder ie.
'Search …'
to anything you want in the PHP Snippet. Try:'Search'
May 18, 2022 at 11:18 pm #2224915LeoI don’t know if I got you correctly. I ended up making three different snippets, one for each language, and changed the placeholder text in each of them. Was that what you meant?
May 19, 2022 at 3:43 am #2225187DavidStaffCustomer SupportWhat i meant was chaning the placeholder text to something Polylang could translate 🙂
But it sounds like using 3 x different snippets is the better solution 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.