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.

Était-ce utile?

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top