WordPress

These two items are responsible for a lot of the spam comments that are entered on a WordPress. Removing them has the potential to cut down on the number you receive.

Adding the first block of code below will remove the author link from existing Recent Posts displays where the author has entered a website URL in the comments area. Note that the author link in the actual comments listing on the post will remain; you would have to manually remove the URL from the Comments section in the Admin dashboard.

The second block of code will remove the Website field (comment URL) from the comments area preventing any further misuse of this “feature”.

Use the Code Snippets plugin to add the code presented and create and activate a new snippet for each block.

As always, read and understand the Sniffle Valve Disclaimer before proceeding.

add_filter( 'get_comment_author_link', 'remove_html_link_tag_from_comment_author_link' );
function remove_html_link_tag_from_comment_author_link ( $link ) {
if( !in_the_loop() ) $link = preg_replace('/<a href=[\",\'](.*?)[\",\']>(.*?)<\/a>/', "\\2", $link);
return $link;
}
add_filter('comment_form_default_fields', 'website_remove');
function website_remove($fields)
{
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}

Similar Posts

2 Comments

    1. Hi Connie,
      They can go in the the functions.php of a child theme (not to edit the parent files) or as I mentioned on the site, I prefer to use the Code Snippets plugin.
      Cheers!
      Lyle

Leave a Reply

Your email address will not be published.