Block Comments Containing Links
Automatically marks as spam any new comment that contains a URL, reducing link-spam without requiring CAPTCHA.
PHPby SnipCraft
php
<?php
/**
* Marks any comment containing a URL as spam before it is saved.
* Returns 'spam' so the comment is caught by the spam queue rather than
* silently discarded, allowing admin review if needed.
*/
if ( ! function_exists( 'scseed_block_link_comments' ) ) {
function scseed_block_link_comments( $approved, $commentdata ) {
if ( 'spam' === $approved ) {
return $approved; // Already flagged elsewhere — do not override.
}
$content = isset( $commentdata['comment_content'] ) ? $commentdata['comment_content'] : '';
if ( preg_match( '#https?://#i', $content ) ) {
return 'spam';
}
return $approved;
}
add_filter( 'pre_comment_approved', 'scseed_block_link_comments', 10, 2 );
}#comments#links#moderation#security#spam