Skip to content

Instantly share code, notes, and snippets.

@msaari
Last active March 5, 2017 04:01
Show Gist options
  • Save msaari/2337fc054fce93a197c5eda42e6dbe08 to your computer and use it in GitHub Desktop.
Save msaari/2337fc054fce93a197c5eda42e6dbe08 to your computer and use it in GitHub Desktop.
WordPress search keyword blocker
<?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