Custom slug in front of search URL

None of the above worked for me. Found another solution by overwriting the search rewrite rules using the search_rewrite_rules filter.

1 – Add this to the functions.php of your theme:

add_filter( 'search_rewrite_rules', function($rules) {
    
     $new_rules = [];

     // New search slug here
     $new_search_slug = 'zoeken';
    
     foreach ($rules AS $key => $value){
        
         $new_rules[str_replace('search', $new_search_slug, $key)] = $value;
        
     }

     return $new_rules;

});

2 – Save the permalinks in the WordPress admin under Settings -> Permalinks.

Now the page https://www.mywebsite.com/zoeken/searchterm is showing the search results page.

Leave a Comment