# Nice Search Slug Translation

**URL:** https://discourse.roots.io/t/nice-search-slug-translation/1033
**Category:** uncategorized
**Created:** 2014-01-09T10:32:31Z
**Posts:** 7

## Post 1 by @Twansparant — 2014-01-09T10:32:32Z

Hi there,

I was wundering if it’s possible to have a custom **nice search** slug?  
When I try to change the **search\_base** in the `roots_nice_search_redirect` function in **lib/cleanup.php** into something like this:

```
$GLOBALS['wp_rewrite']->search_base = __('zoeken', 'mytextdomain');
$search_base = $wp_rewrite->search_base;
```

and flush my permalinks afterwards, nice search stops working and gives me a 404 page.  
I also tried changing these lines with the same result:

```
$search_base = 'zoeken';
```

and

```
wp_redirect(home_url("/zoeken/" . urlencode(get_query_var('s'))));
```

Is there something else I need to change somewhere?

Thanks!

---

## Post 2 by @Foxaii — 2014-01-09T11:14:12Z

I wouldn’t do this.

The change you made to `$wp_rewrite->search_base` should be done on `init` not during the `template_redirect`.

You would also have to manually add each of the possible options for the search slug to the rewrite rules, or the redirect will 404.

---

## Post 3 by @Twansparant — 2014-01-09T11:31:06Z

Thanks for your reply!  
I got it working by adding the search rewrite rules and changing the `$wp_rewrite->search_base` in a seperate on init function.

This is my code:

```
/**
 * Rewrites search base slug from 'search' to 'zoeken'
 */
function roots_nice_search_rewrite() {
	$GLOBALS['wp_rewrite']->search_base = __('zoeken', 'mytextdomain');
}
add_action( 'init', 'roots_nice_search_rewrite' );

/**
 * Rewrites rules for search slug
 */
function my_search_rewrite_rules($rules) {
	$search_base = $wp_rewrite->search_base;
	foreach($rules as $rule => $target){
		$new_rule = str_replace('search', $search_base, $rule);
		unset($rules[$rule]);
		$rules[$new_rule] = $target;
	}
	return $rules;
}
add_filter('search_rewrite_rules', 'my_search_rewrite_rules');
```

---

## Post 4 by @Foxaii — 2014-01-09T14:12:27Z

I don’t think that will work unless you flush the rewrite rules on every page load.  
Try changing the language and searching again.

---

## Post 5 by @Twansparant — 2014-01-10T09:52:15Z

It does work for me. My search url is now: [http://mydomain.com/zoeken/test](http://mydomain.com/zoeken/test)

Which returns the searchresults perfectly for ‘test’, even with working pagination.

---

## Post 6 by @Foxaii — 2014-01-10T12:54:21Z

Because ‘zoeken’ is translatable, anyone using your site in a different language will get a 404 because the rewrite rules will not support the translated term until the rewrite rules are flushed.

So this will work fine long if everyone is using the same language or you use ‘zoeken’ as a static (i.e. non-translatable) string.

---

## Post 7 by @Twansparant — 2014-01-13T16:37:18Z

Okay, got it. Thank you!  
For now the site is only in one language which wasn’t English, so _search_ was the only non translated slug left.
