Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found this snippet online …

function search_url_rewrite_rule() {
    if ( is_search() && !empty($_GET['s'])) {
        wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
        exit();
    }   
}

add_action('template_redirect', 'search_url_rewrite_rule');

This transforms my ?/s=term into /search/term which is almost what I want. I'd like to use the german word "suche" instead of "search" inside my permalinks.

I thought of changing home_url("/search/") to simply home_url("/suche/") but that doesn't work.

How can I make that happen?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The reason it isn't working is because you haven't told WordPress how to handle that page. You can do so by applying a rewrite rule in the following manner.

add_action( 'init', 'wpse_63716_search_rule' );
function wpse_63716_search_rule(){
    add_rewrite_rule('^suche/([^/]*)?', 'index.php?s=$matches[1]', 'top');
}

Don't forget to flush the permalinks after adding the above code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.