Skip to content

Instantly share code, notes, and snippets.

@lumpysimon
Last active February 5, 2025 21:46
Show Gist options
  • Save lumpysimon/dd2c8043bc271acb497dc2dd8368ebde to your computer and use it in GitHub Desktop.
Save lumpysimon/dd2c8043bc271acb497dc2dd8368ebde to your computer and use it in GitHub Desktop.
Exclude spammy searches from SearchWP
add_filter( 'searchwp\statistics\log', 'my_log_filter', 10, 2 );
function my_log_filter( $enabled, $query ) {
$search_string = $query->get_keywords();
$long = ( strlen( $search_string ) > 30 );
$www = ( 'www' === substr( $search_string, 0, 3 ) );
$slashes = ( false !== strpos( $search_string, '/' ) );
if ( $long or $www or $slashes ) {
return false;
}
return true;
}
@DirectorObi
Copy link

This sounds so dumb but where did you drop this file in your code? Like in your child theme folder?

@lumpysimon
Copy link
Author

Hi @DirectorObi - Yes, if you're using a child theme you should put it in the functions.php file in the child theme folder.

@DirectorObi
Copy link

Perfect! Thanks so much for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment