Redirect Search Query in WordPress

In this post, Pioneer Web Design will show you how to Redirect Search Query in WordPress without a plugin. Steps by step instructions are given.

Redirect Search Query in WordPress

I was attempting to redirect a search query using the built in search form in WordPress and needed to do some research to get this to work. Attempting on one site, what I thought should work did not! That site uses a theme that adds an action hook to `get_search_query`, (more later) so I just tried on a site that uses the default (child) theme – this one.

Add this to functions.php (best in a Child Theme):

add_action('template_redirect', 'redirect_my_term' );function 
redirect_my_term() {if (is_search()) { 
if (preg_match('/b[search term]b/i', get_search_query()) == TRUE){ wp_redirect
(home_url("/your_slug/")); die(); }

Note: [search term] = term, do not leave brackets.
/your_slug/ = the slug for the page including both /’s

Is working here, search for `qqvxy` and you will end up at /category/security.