Pretty Search URLs
Redirects ?s=term searches to /search/term/ when pretty permalinks are enabled, which gives cleaner, shareable URLs.
Opens WPIDE on
Code
add_action( 'template_redirect', function () {
if ( ! is_search() || ! get_option( 'permalink_structure' ) || ! isset( $_GET['s'] ) || 1 !== count( $_GET ) ) {
return;
}
$term = get_search_query( false );
if ( '' !== $term ) {
wp_safe_redirect( home_url( '/search/' . rawurlencode( $term ) . '/' ) );
exit;
}
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.