Spammers love WordPress comment forms. They use bots that automatically post spam comments with malicious links in hundreds of websites. Their goal is to gain SEO juice out of your site. But what if there is a way to discourage them from using such tools on your website? Its simple, we can disable the website or URL field in the comment form, and it will not let them post any spammy links to your site.
How to remove website URL field from WordPress comment form without plugin
By default, WordPress comment form has name, email, website url and comment field. There is a comment_form_default_fields filter in /wp-includes/comment-template.php file in WordPress core, which allows you to filter or change all the default comment form fields. So, we can use comment_form_default_fields
filter and unset the url field. Next, we will remove the make_clickable
function from comment_text
filter to disable auto-linking of urls from comment text. Here is all the code snippet to paste in functions.php file of your website’s active theme.
<?php /* Filter to unset website URL Field from WordPress comment form */ add_filter('comment_form_default_fields', 'wptips_remove_website_field'); function wptips_remove_website_field($fields){ if(isset($fields['url'])) unset($fields['url']); return $fields; } /* remove make_clickable filter to disable autolinking of urls in WordPress comment text */ remove_filter( 'comment_text', 'make_clickable', 9 );
Strip comment author link from comment list
You can also unlink all the comment author names from the comment list. To achieve this, use get_comment_author_link
filter and remove the link via strip_tags
function.
<?php // strip comment author links function wptips_strip_comment_author_links( $link, $author, $comment_id ){ return $author; } add_filter( 'get_comment_author_link', 'wptips_strip_comment_author_links', 10, 3); ?>