Last active
February 5, 2025 21:46
-
-
Save lumpysimon/dd2c8043bc271acb497dc2dd8368ebde to your computer and use it in GitHub Desktop.
Exclude spammy searches from SearchWP
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
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; | |
} |
Hi @DirectorObi - Yes, if you're using a child theme you should put it in the functions.php
file in the child theme folder.
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
This sounds so dumb but where did you drop this file in your code? Like in your child theme folder?