Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install honeypot spam prevention to your wordpress to reduce spam comments http://www.wppicker.com/how-to-install-honeypot-spam-blocking-for-wordpress/
/*
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;
}
@DenisCGN
Copy link

DenisCGN commented Feb 4, 2022

Hello @vijujohns
does this honeypot for comments still work on WP5.9?
Thanks and greetings,
Denis

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