pixel-d
11/29/2017 - 6:57 PM

Pretty Search URL in WordPress

Change Search URL in Wordpress from /?s=xyz to /search/xyz

/**
 * Rewrite URL for search queries from /?s=xyz to /search/xyz
 *
 * http://wpengineer.com/2258/change-the-search-url-of-wordpress/
 */
 
function lnd_change_search_url_rewrite() {
  if ( is_search() && ! empty( $_GET['s'] ) ) {
    wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
    exit();
  } 
}
add_action( 'template_redirect', 'lnd_change_search_url_rewrite' );