Created
June 17, 2020 23:02
-
-
Save the-sufi/2a9c67256f97a785c216b89679ffddb1 to your computer and use it in GitHub Desktop.
Change WordPress default search URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Modify Default Search URL | |
* old url: domain.com?s=[search_term] | |
* new url: domain.com/search/[search_term] | |
*/ | |
function dctit_change_search_url() { | |
if ( is_search() && ! empty( $_GET['s'] ) ) { | |
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) ); | |
exit(); | |
} | |
} | |
add_action( 'template_redirect', 'dctit_change_search_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment