Change the default search URL of WordPress
Use Case Scenario:
A WordPress website wants to change the default search URL since it’s not SEO friendly.
Open functions.php in wordpress theme directory folder inside wp-content->themes->theme name folder then copy and paste the code below inside functions.php
function change_search_url() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url("/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'change_search_url' );
Watch the video tutorial in YouTube
Support WeHelpCode by subscribing to our YouTube Channel