I would like to block certain keywords (multiple keywords, banned keywords like fuk, sit etc.) from searching on Wordpress blog and show/redirect visitor/member (searcher) to different page.

Used this code but it returned 500 internal server error:

    add_action('wp', 'check_search');
function check_search() {

    global $wp_query;

    if (!$s = get_search_query())
        return false;

    if preg_match('/^(word1|word2|word3)$/', $s)) {


How to fix and How to do the redirection?

  • It works for me if I fix the syntax error: if ( preg_match. Always turn on debugging during developing. – Max Yudin Dec 21 '18 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.