I'd like to block some specific banned keywords from searching and redirect to custom wordpress page when someone search these specific keywords on WP.
I'm gonna use the below code for banning these keywords on search on functions.php:
add_action( 'pre_get_posts', 'wpse338558_intercept_banned_keywords' );
function wpse338558_intercept_banned_keywords ($query) {
$banned = array ('word1','word2','word3');
if (in_array ($query->query_vars['s'], $banned)) $query->s = '';
}
I expect a redirection to specific wp page with template_redirect
code but couldn't write the proper code for it.
How can i place the redirection?