Skip to content

Instantly share code, notes, and snippets.

@wpgaurav
Created April 8, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpgaurav/af7b6e605dcc0462f443fd475eb3c041 to your computer and use it in GitHub Desktop.
Save wpgaurav/af7b6e605dcc0462f443fd475eb3c041 to your computer and use it in GitHub Desktop.
Reduce Comment Spam WordPress
<?php
// Copy this code in your theme's functions.php file before closing ?>
// This removes website field from comment forms
add_filter('comment_form_default_fields', 'website_remove');
function website_remove($fields)
{
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}
// This removes existing author URLs linked to author names
add_filter( 'get_comment_author_link', 'rv_remove_comment_author_link', 10, 3 );
function rv_remove_comment_author_link( $return, $author, $comment_ID ) {
return $author;
}
// Some bloggers, link-building muddleheads may spam your comment area with multiple URLs. You can get rid of those by putting this code
function gt_comment_post( $incoming_comment ) {
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
$incoming_comment['comment_content'] = str_replace( "'", '&apos;', $incoming_comment['comment_content'] );
return( $incoming_comment );
}
function gt_comment_display( $comment_to_display ) {
$comment_to_display = str_replace( '&apos;', "'", $comment_to_display );
return $comment_to_display;
}
add_filter('preprocess_comment', 'gt_comment_post', ’, 1);
add_filter('comment_text', 'gt_comment_display', ’, 1);
add_filter('comment_text_rss', 'gt_comment_display', ’, 1);
add_filter('comment_excerpt', 'gt_comment_display', ’, 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment