Documentation

View the installation guide, browse the Knowledge Base, find out about SearchWP's many hooks, get support

How to change your search query parameter from ‘s’ to something else

One of the great things about WordPress is the ability to customize it in any number of ways. WordPress uses many sensible defaults, one of which is how native searches are triggered.

By default, a query parameter of s triggers WordPress’ search, resulting in a URL that looks something like this:

https://mysite.com/?s=coffee

If you’d like to instead use something that more clearly describes what’s happening at this URL, you may want to use search_query as your query parameter instead of s. You can do that by adding something like this to your theme’s functions.php:

<?php
add_filter('init', function(){
global $wp;
$wp->add_query_var( 'search_query' );
$wp->remove_query_var( 's' );
} );
add_filter( 'request', function( $request ){
if ( isset( $_REQUEST['search_query'] ) ){
$request['s'] = $_REQUEST['search_query'];
}
return $request;
} );
view raw functions.php hosted with ❤ by GitHub

Once that’s in place, your search URLs will now look like this:

https://mysite.com/?search_query=coffee

Which may suit your needs a bit better.

Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP