Easy way to get rid of on WordPress Spam Comment without any plugins
There are lots of plugins to prevent spam comment on WordPress but We can prevent comment spamming without any plugins.
Typically spamming tools target a site / WordPress comment field without any target, even if the server-side comments and comments fields for protection in the field understand that the bot can send data to fill.
We’ll use JavaScript for spam proof form field. Let’s go to the code.
At first, we add the code below at WordPress Theme’s JavaScript file.
$( "#commentform" ).on('submit', function(e){ $( this ).append( '<input type="hidden" name="is_legal_comment" value="1">' ); });
Now, add the code below in functions.php
add_filter( 'preprocess_comment', 'verify_no_spam_comment' ); function verify_no_spam_comment( $commentdata ) { if ( ! isset( $_POST['is_legal_comment'] ) ) wp_die( __( 'You are bullshit' ) ); return $commentdata; }
It is very simple, If anyone disable javascript, then its shows error and form can’t be submitted.
This article originally wrote by Emran Ahmed on wpcookbook.net in Bengali. I just trying to translate into English. Sorry for my poor English. 🙂