As your WordPress website/blog grows, the number of spam comments would also increase. There are good anti-spam plugins services such as Akismet, Antispam Bee, etc. However, still we can see some spam comments coming in with website URLs. It’s a good idea to remove the Website field from the comment box itself.
In this post, we’ll show you how to remove the “website” field, as well as remove the word “website” from the consent checkbox and/or completely change the text of comment consent as of your choice.
Before
After
To achieve this, you need to add the below code snippet(s) to your website. However, editing the theme files is not a good idea. Here are our recommendations;
1. Add the snippets to your child theme’s functions.php
file – If you don’t have a child-theme go with the next option. But consider having a child-theme, it’s a must for any WordPress site I would say.
2. Install snippets using Code Snippets plugin – This is one of the easiest & flexible methods of installing code snippets on WordPress. You may activate/deactivate a snippet at any time you want to. Also if you change your theme, you don’t have to add snippets again to your new child theme.
Note: Before doing any changes to your website, make sure you backup your database and/or website files.
Remove the “website” field
Add below code to your child theme’s functions.php or create a new snippet on the Code Snippets plugin.
add_filter('comment_form_default_fields', 'codechilli_unset_url_field');
function codechilli_unset_url_field($fields){
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}
Edit consent text
The default text that comes with WordPress is Save my name, email, and website in this browser for the next time I comment. You may add any text you wish to. Just replace the below text in line 5:
Remember my name & email in this browser for the next time I comment.
add_filter('comment_form_default_fields', 'codechilli_change_comment_consent_text');
function codechilli_change_comment_consent_text($fields)
{
$commenter = wp_get_current_commenter();
$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"/>' . '<label for="wp-comment-cookies-consent">' . __('Remember my name & email in this browser for the next time I comment.') . '</label></p>';
return $fields;
}
That’s it. Now you know how to customize the comment box. Please let us know how it works for you 😊
0 Comments