Do not allow to search certain words

I would like to delete (not allow) searches with certain keywords (eg “of”, “a”).

If the search is done using exactly these terms, do not return anything or redirect to 404 page …

Read More

Thanks guys.

Related posts

Leave a Reply

1 comment

  1. Try this in your functions.php, and change news for whatever you want to be blocked in your site.

    add_action('wp', 'check_search');
    function check_search() {
    
        global $wp_query;
    
        if (!$s = get_search_query())
            return false;
    
        if (preg_match('/news/', $s)) {
            $wp_query->set_404();
            status_header(404);
            get_template_part(404);
            exit();
        }
    
    }
    

    Hope it helps.