0

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?

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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