How do I disable the search param /s?=

Hello, I am using the Pro theme and am building a custom search in my child search via creating a search.php file. I noticed a few bugs when attempting to use the default search param /s? so I switched it in my functions to use a different parameter key.

Now, how do I disable the default ?s= by the Pro theme?

The issue with using ?s= and my custom search.php theme file is that certain queries for example “test” breaks the page for some reason.

Thanks

Hello Jing,

Thank you for the inquiry.

You can disable the default search parameter using this hook in the functions.php file:

// Disable the ?s= parameter in WordPress
function x_disable_search_parameter() {
    if ( isset($_GET['s']) && !empty($_GET['s']) ) {
        wp_redirect(home_url('/'));
        exit;
    }
}

add_action('template_redirect', 'x_disable_search_parameter');

This will redirect the visitor to the homepage, but you can adjust the wp_redirect argument if needed.

Best regards,
Ismael