Weglot
The Weglot translation plugin is not a translation plugin that FacetWP officially supports or integrates with. For this, use WPML or Polylang instead. However, we’ve seen users using Weglot successfully with FacetWP, with the fixes described below. These may not cover all translation scenarios, but they will get you started.
For additional issues, you could look into Weglot’s range of translation hooks, which can be used to add elements to the translations. For example, the weglot_words_translate hook could be useful to target specific words that are literally in your source code. If you manage to solve specific FacetWP-related issues with these hooks, please let us know, and we’ll add them to this page.
What Weglot does is detect all the words in your page’s HTML and translate them. To do this, it parses the DOM in PHP and detect the inner text of HTML nodes, including some pre-defined attributes, like the placeholder attribute in an <input> node or the alt attribute of an <img> node. This ensures all the text in your page is detected and gets translated. However, this is not enough to get facet choices and Search facet results translated correctly:
Translate facet choices on first page load
Facet choices will be automatically translated after an AJAX refresh (after using facets), but not before that. To translate facets also on first page load, implement one of the two approaches below. Either one will work; there is no need to use them both at the same time.
The first approach is recommended for performance reasons, because it does not force FacetWP to do an extra AJAX refresh on page load.
Option 1: Add FacetWP’s facet choices and setting labels to the Weglot translations
Add the following snippet to your (child) theme’s functions.php. It uses the weglot_get_regex_checkers hook to add all translatable FacetWP data that is available in the window.FWP_JSON object to Weglot’s translations.
The regex in the first argument of the RegexChecker() function matches FacetWP’s window.FWP_JSON object that is in the page source. The regex will still work if attributes are added to the <script> tag with the wp_inline_script_attributes filter hook.
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
// Translate FacetWP facet choices and settings in Weglot add_filter( 'weglot_get_regex_checkers', function( $regex_checkers ) { $regex_checkers[] = new \Weglot\Parser\Check\Regex\RegexChecker( '#<script[^>]*>\s*window\.FWP_JSON\s*=\s*([\s\S]+?);\s*</script>#', 'JSON', 1, array('a11y', 'no_results', 'no_results_text', 'preload_data') ); return $regex_checkers; });
Option 2: Disable FacetWP’s preloader
The alternative to option 1 is to disable FacetWP’s pre-loader with the facetwp_use_preloader hook.
FacetWP “preloads” its data on first page load, and stores it in the FWP_JSON.preload_data object on the page. This data is then used to render the facets almost instantly, without fetching the data with an AJAX call (which happens when using facets).
This does not work with Weglot. The solution is to either add all that data to Weglot’s translations with the snippet above, or you can force FacetWP to do an AJAX refresh on first pageload, by adding the following line to your (child) theme’s functions.php:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_use_preloader', '__return_false' );
Be aware that this will cause your facets to load slightly slower the first time because FacetWP has to fetch the data first, instead of using it immediately.
Fix Search facet search results

To enable WP search in the user’s language, enable Weglot’s “Search WordPress” setting in the Weglot settingss. This will translate search keywords to the original language and then process them as a normal search query. See this page for more info on how this works.
However, this setting only works to translate search keywords in the normal WP search input and results page, not when using a Search facet. To fix this, add the following snippet to your (child) theme’s functions.php. It will translate the search keywords to the original language, and pass them back into the Search facet’s search arguments, using the facetwp_search_query_args hook.
Note that the facetwp_search_query_args hook only works for Search facets that have their search engine set to “WP Default“.
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
/** * Translate the search string back to the original language in Weglot, * so that the "WP Default" engine returns the right posts. */ add_filter('facetwp_search_query_args', function ($search_args, $params) { if (empty($search_args['s'])) { return $search_args; } if (! function_exists('weglot_get_service') || ! function_exists('weglot_get_destination_languages') || ! function_exists('weglot_get_current_language')) { return $search_args; } $language_services = weglot_get_service('Language_Service_Weglot'); if (! $language_services || ! method_exists($language_services, 'get_original_language')) { return $search_args; } $parser_services = weglot_get_service('Parser_Service_Weglot'); if (! $parser_services || ! method_exists($parser_services, 'get_parser')) { return $search_args; } $parser = $parser_services->get_parser(); if (! $parser || ! method_exists($parser, 'translate')) { return $search_args; } $original_language = $language_services->get_original_language()->getInternalCode(); $current_language = weglot_get_current_language(); if ($original_language === $current_language) { return $search_args; } $destination_languages = weglot_get_destination_languages(); foreach ($destination_languages as $destination) { if ( isset($destination['language_to'], $destination['custom_code']) && $destination['language_to'] === $current_language && ! empty($destination['custom_code']) ) { $current_language = substr($destination['custom_code'], 0, 2); break; } } $search_args['s'] = $parser->translate($search_args['s'], $current_language, $original_language); return $search_args; }, 10, 2);