Question

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 ...

Thanks guys.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top