I want to change the search url to something like this
http://simply.mmag.in/blog/?s=coaching
Where as my current search result shows which is recommended by most user and article
http://simply.mmag.in/blog/coaching
Code which i am using for the above search result
function wpb_change_search_url() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/blog/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'wpb_change_search_url' );
and the base url code
function re_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->search_base = 'blog';
$wp_rewrite->flush_rules();
}
add_action('init', 're_rewrite_rules');
How can i get search result like this
http://simply.mmag.in/blog/?s=coaching
2
Answers
What happends if you just remove or comment out your
wpb_change_search_url()
function?Have you tried to just remove this custom code? WordPress by default uses ?s= in urls, and code used by you just rewrite it.