Automatically spam comments with a very long url

Spam comments is a fact of life if you manage a blog. Most of these spam comments consist of very long URLs. Automatically marking comments with long URLs as spam can be very useful in combating spammers.

Useful Read: How to Remove Website URL Field from Comment Form

The following WordPress code snippet will automatically mark comments with URLs longer than 50 characters as spam.

<?php

  function rkv_url_spamcheck( $approved , $commentdata ) {
    return ( strlen( $commentdata['comment_author_url'] ) > 50 ) ? 'spam' : $approved;
  }

  add_filter( 'pre_comment_approved', 'rkv_url_spamcheck', 99, 2 );

?>

Source: https://css-tricks.com/snippets/wordpress/spam-comments-with-very-long-urls/

0 Comments

Leave a Comment.