Remove Links & Other Spam from Comments in WordPress

Comments are no longer good for SEO but if you can’t still get rid of it, manage it right.

Some bloggers, link-building muddleheads may spam your comment area with multiple URLs. You can get rid of those by putting this code in your child theme’s functions.php file.

<?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);
?>

First time here? Try these resources...

  1. Best VPN Services
  2. Best WordPress Hostings
  3. Best WordPress Themes
  4. Best WordPress Plugins
  5. Best Gutenberg Block Plugins
  6. Best Email Marketing Plugins
  7. Best WordPress Caching Plugins
  8. Best WooCommerce Plugins
  9. Email Marketing Guide for Beginners
  10. Best Small Business Apps
  11. Best Business Name Generators
  12. Top Plagiarism Checkers
  13. Free Web Hosting Services
  14. Best Online Businesses to Start
  15. Best Online Course Platforms
  16. Best Online Casinos in India
  17. Best Affiliate Marketing Programs
  18. More Resources...

Get useful blogging, marketing and learning resources, delivered to your mailbox. Plus, get regularly updated with extra tools & guides to help you learn, grow and earn better.

Get 17+ exclusive e-books & templates for free, to begin with. 🎁