SearchWP

This Documentation is for SearchWP Version 3

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.

[wpforms id="3080"]