If you get a lot of spam comments where users are trying to get back-links to their sites then use this WordPress hack/tip to remove the URL field altogether from your WordPress comments form.
This way no one will be able to leave a site URL with the comment and hopefully it will discourage the spammers and you will get more genuine comments on your site.
The WordPress Filter to Use: comment_form_default_fields
We are going to utilize WordPress’s “comment_form_default_fields” filter to remove the URL field from your site’s comment form.
This comment filter allows you to modify the array of default fields. You can also use the “comment_form_default_fields” filter to add a new field or remove a single field.
How to Remove the URL Field
Simply copy and paste the following snippet of code into your “functions.php” file of your WordPress theme and then check the comment form of a post or page:
function remove_url_from_comment($fields) { unset($fields['url']); return $fields; } add_filter('comment_form_default_fields','remove_url_from_comment');
Test this snippet of code on your test site first and if everything goes well then make the changes live.
Remove the Author or Email Field From the Comment Form
You can also remove the “Author” or “Email” field from the comment from using this same approach:
- author
Example Code:
function remove_email_from_comment($fields) { unset($fields['email']); return $fields; } add_filter('comment_form_default_fields','remove_email_from_comment');