The snippet
When using the search widget in Elementor in conjunction with Polylang, once you search, the slug does not contain the language code. Here’s a nifty solution that let’s you fix this.
add_action('elementor/widget/render_content', function($content, $widget) {
if ($widget->get_name() == 'search-form' && function_exists('PLL')) {
$dom = new DomDocument;
$dom->loadHTML($content);
$nodes = $dom->getElementsByTagName('form');
$node = $nodes[0];
$node->setAttribute('action', PLL()->curlang->search_url);
$content = $dom->saveHTML($node);
}
return $content;
}, 10, 2);
Credits go to maryisdead for figuring this out, it can be such a life saver that I wanted to share this!