De Belser Arne Profielfoto

Arne De Belser

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

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x