Last active
February 4, 2022 07:28
-
-
Save vijujohns/b0b8582d50abc1bc508a to your computer and use it in GitHub Desktop.
Install honeypot spam prevention to your wordpress to reduce spam comments http://www.wppicker.com/how-to-install-honeypot-spam-blocking-for-wordpress/
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
/* | |
This code adds a hidden text field to the comment form to trap spam bots. | |
Add these code snippet at the end of functions.php. | |
No other setting needed. | |
*/ | |
//Add an invisible field to comment form box | |
add_action('comment_form', 'wpp_add_honeypot'); | |
function wpp_add_honeypot($postID) { | |
//Adding a invisible textarea with name igotyoubot for spambots, visitors won't see this. | |
echo '<p style="display:none">'; | |
echo '<textarea name="igotyoubot" cols="100%" rows="10" autocomplete="off"> </textarea>'; | |
echo '<label for="igotyoubot">' . __("I don't like an input here. You Must Leave This Empty") . '</label>'; | |
echo '</p>'; | |
} | |
//Check if comment is a spam | |
add_filter('pre_comment_approved', 'wpp_detect_honeypot'); | |
function wpp_detect_honeypot($comment_status) { | |
if (!empty($_POST['igotyoubot'])) { // Mark as spam if bot filled out the hidden textarea | |
$comment_status = 'spam'; | |
} | |
return $comment_status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @vijujohns
does this honeypot for comments still work on WP5.9?
Thanks and greetings,
Denis