Last active
March 5, 2017 04:01
-
-
Save msaari/2337fc054fce93a197c5eda42e6dbe08 to your computer and use it in GitHub Desktop.
WordPress search keyword blocker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add this function to theme functions.php */ | |
add_filter( 'pre_get_posts', 'rlv_block_search' ); | |
function rlv_block_search( $query ) { | |
if (!empty($query->query_vars['s'])) { | |
$blacklist = array( '大奖', 'q82' ); // add blacklist entries here; no need for whole words, use the smallest part you can | |
foreach( $blacklist as $term ) { | |
if( mb_stripos( $query->query_vars['s'], $term ) !== false ) exit(); | |
} | |
} | |
} | |
/* Stop here */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment