Home » Show search results with language specific slug while running Polylang

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!

Do you have any questions? Please feel free to leave a comment below, and I will do my best to respond as quickly as possible.

If you’re interested in more tutorials or engaging content, be sure to check out my YouTube channel

Abonneer
Laat het weten als er
guest
0 Comments
Oudste
Nieuwste Meest gestemd
Inline feedbacks
Bekijk alle reacties
0
Zou graag je mening willen weten, laat een reactie achter.x