WordPress is the most customizable and easy platform for blogging. WordPress may uses many sensible defaults one of which is how native searches are triggered.
A query parameter of s triggers WordPress search, resulting in a URL that looks something like this, by default:
https://mywebsite.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 Original Code From GitHub Note: This may cause problem when theme updates to default. It may remove all your added codes.
Once that’s in place, your search URLs will now look like this:
Once that’s in place, your search URLs will now look like this:
https://mywebsite.com/?search_query=coffee
Which may suit your needs a bit better.
Which may suit your needs a bit better.
Post a Comment
0 Comments