Polyglot search fix

While implementing the Polyglot plugin on a WordPress site I was working on, I found a bug related to the search form: the plugin appends “/lang-pref/en/” (or whatever other ISO language code) to the search string (in the URL - when using “pretty permalinks” AKA URL rewriting).

This does not directly affect the first search, but the search field is then filled with “my search string/lang-pref/en”, which is confusing for the visitor.

A quick solution is to filter the search query and remove the said string:

/* Clean the search URL */
function polyglot_clean_search_URL () {
return preg_replace('@/lang-pref/[a-z]{2}/@i','',get_search_query());
}
add_filter('the_search_query', 'polyglot_clean_search_URL', 1);

You can either add this code to your theme’s functions.php, or to the plugin’s file, at the end.

Article Info

This article was read 3030 times.