wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Rewrite the search results slug to /search/term

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will rewrite the search results URL to /search/ that will give you a results URL like http://wpsnipp.com/search/searchterm

snippet :  PHPcopy
function search_url_rewrite_rule() {
	if ( is_search() && !empty($_GET['s'])) {
		wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
add_action('template_redirect', 'search_url_rewrite_rule');

Did you like this post? If so please share it with your friends. Thanks!

  • Anonymous

    Is there some SEO advantage by using this instead of the default URL?
    Nice function BTW, i’ll use it.

    • http://wpsnipp.com Kevin Chard

      To be honest I don’t think it is that big of a help to SEO however if you have pretty links enabled this continues this look rather then ?s= .

  • http://twitter.com/luissacristan Luis Sacristán

    Thanks for the snipp, but there is a problem when you try to search words with accents (á, é, í, ó, ú) or others letters (ñ, ç, …)

    You have to decode the search term in the query_vars and in the search_query. Here is my code

    function you_search_filter($s) {
    return urldecode($s);

    add_filter(‘get_search_query’, ‘you_search_filter’);

    add_filter(‘the_search_query’, ‘you_search_filter’);

    add_action(‘parse_query’, ‘you_query_vars_search_filter’ );

    function you_query_vars_search_filter( $qvars ) {
    $qvars->query_vars[‘s’] = urldecode($qvars->query_vars[‘s’]);
    return $qvars;


    Hope it could be useful