Wordpress search result page in bilingual website

I have a bilingual site, my search results page only shows in the site’s primary language. How should I translate it?

I used the polylang plugin and the entire site is translated correctly, only the search results are always displayed in the primary language.

a This is a common issue with multilingual WordPress sites using Polylang—the search results page often defaults to the primary language, even if the user is browsing in a different language.

Why this happens:

Polylang doesn’t automatically filter WordPress search queries by language unless you tell it to. The search results loop (WP_Query) needs to be filtered to only show results in the current language.


Solution: Filter search results by current language

You can fix this by adding a snippet to your theme’s functions.php file (or a custom plugin). Here’s how:

function filter_search_by_current_language($query) {
    if ($query->is_search && !is_admin() && function_exists('pll_current_language')) {
        $query->set('lang', pll_current_language()); // Add current Polylang language to the search query
    }
    return $query;
}
add_filter('pre_get_posts', 'filter_search_by_current_language');

This snippet tells WordPress to limit search results to the current Polylang language whenever a search is performed.


Bonus: Test if it’s working

  1. Go to the front-end of your site.
  2. Switch to your secondary language (e.g., French).
  3. Perform a search.
  4. You should now only see results in the selected language, and the page itself will be in that language as well.

Additional Tips

  • Ensure you have translated content for the keywords you’re testing.
  • Check your search template (search.php) if you’ve customized it—some custom queries might override this behavior.
  • If using Ajax-based search (live search), you’ll need to adapt the Ajax query too.

Let me know if you need help applying this in a specific theme or with Ajax.