WpCode.net

Daily Wordpress Code Snippet

How to rewrite the serch results slug

| 0 comments

Pin It

This snippet help you to create a new .htaccess rewrite rule for the search.php file. It’s rewrite the search query from “yourblog.com/?s=researchedterm” in “yourblog.com/slugyouwanttouse/researchedterm”.

You just need to add this snippet in your function.php Continue reading

function wpc_search_url_rule() {
	if ( is_search() && !empty($_GET['s'])) {
		wp_redirect(home_url("/SLUG YOU WANT TO USE/") . urlencode(get_query_var('s')));
		exit();
	}
}
add_action('template_redirect', 'wpc_search_url_rule');

Leave a Reply

Required fields are marked *.

*