Archived topic
Polylang GP conflict
15 replies · Started by John Dowling on January 25, 2018
Hi Tom.
Overall I am loving GP!
I also have polylang installed to have both french and english. One problem.
The search box works fine in english and delivers only english pages.
On the french side it never finds anything.
If I use the built-in wordpress search widget both languages work perfectly
If I turn off polylang the GP search function works but delivers results from both languages.
Can you helpÉ
Hi there,
Any chance you can turn on the core search widget so I can inspect the code?
Let me know :)
Sure. I activated the search box in the footer of both languages.
Just dove into their code a bit, let's try this function:
add_filter( 'generate_navigation_search_output', 'tu_polylang_navigation_search' );
function tu_polylang_navigation_search( $search ) {
if ( ! function_exists( 'pll_current_language' ) ) {
return $search;
}
printf( // WPCS: XSS ok, sanitization ok.
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
</form>',
esc_url( home_url() ) . '/' . pll_current_language(),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
}
Let me know :)
Where does it go?
One of these methods here: https://docs.generatepress.com/article/adding-php/
Code snippet is usually what I use unless you are using a child theme.
Installed Code snippet. Set to run everywhere. Sadly no luck
I just dug through some of the Polylang documentation and made a change to the code above.
Can you try it and let me know?
Thanks!
Now both languages don't work. Any search give: Oops! That page can’t be found.
(When the snippet is deactivated and you search for something that isn't there you get "Nothing found")
Grr. Is the snippet still active?
it is now.
The search in english works. But if you then search from the results page you get the error message
Alright, let's try this again: https://generatepress.com/forums/topic/polylang-gp-conflict/#post-480638
I believe I'm using the right function now.
Works!! Thanks!
Only bug is if you click on English when you are in the French search results page you get the file not found message. Then if you click again you go to english home page. Maybe that's a separate language switch problem?
That may be worth checking with Polylang support about. If it's something we need to do on our end, I'll see what I can do :)
Thanks!
I think I'll leave it for now as not likely thing for people to do.
Thanks for your help!!