Remove the URL and Email from the Comments Box in WordPress
Posted onI’ve talked a lot in the past about how important the comment section is for any blog regardless of whether or not it has regular or sporadic readership. And one of the best ways to build a community is allowing people to visit other people’s websites that they leave via the “URL” field when posting a comment. However, a lot of people have concern that this merely encourages spammers. Moreover, websites that are eager to offer privacy might feel hesitant in asking individuals for their email ID merely for commenting.
Yet other websites might want to make commenting as seamless as possible with minimal entry of information. For this reason, they might want to do away with the email and URL fields entirely. In this article, let’s take a look at how to achieve this and customize the comment fields to your taste. I’ll first look at the general method for themes which don’t implement their own comment forms. Then we’ll take a look at a theme like Genesis which implements its own comment form and is therefore slightly different.
Removing the Email and URL Fields
A regular WordPress theme like TwentyFifteen, uses the default comment form functions. Knowing this, we can make use of some useful filters to change the comment fields. A regular comment box has three pieces of information the user can enter – two of which are mandatory.
Users are forced to enter the name as well as the email ID, but can choose to leave the website field blank. To get rid of the email and the URL box, open up your functions.php file or any other place where you insert custom WordPress code and paste in the following:
function remove_email_url($fields) { unset($fields['url']); unset($fields['email']); return $fields; } add_filter('comment_form_default_fields', 'remove_email_url');
Using the “comment_form_default_fields” filter, we can simply unset the two parameters of URL and email and return the fields array with the modified information. When you save your snippet and visit your comment form again, these two fields should now be missing:
However, you still won’t be able to comment because the email ID is a required field for WordPress commenters. So we need to make it optional by visiting the Settings-> Discussion page from the WordPress administration dashboard. Here, we can simply uncheck the option that makes the email mandatory:
This should get you all set up with removing the email and URL fields for regular WordPress themes. But the same code want to work with something like Genesis which has its own comment form section. Let’s see how to achieve the same effect there as well.
Removing the Email and URL in Genesis
Genesis has its own filter called “genesis_comment_form_args” which we can tap into for removing the fields. As before, copy and paste the following into your Genesis child theme’s functions.php:
function remove_genesis_url_email( $args ) { unset( $args['fields']['url'] ); unset( $args['fields']['email'] ); return $args; } add_filter( 'genesis_comment_form_args', 'remove_genesis_url_email' );
The “$fields” array resides within the larger “$args” array, so we need to delve a bit deep inside to reach the variables. But once we know where to find them, we can unset them as easily as before. Here’s the effect of the above code once implemented:
If you choose to remove these two fields however, keep in mind that your commenters will be faceless entities both to you as well as to the other readers on your website. The lack of URL fields means that others won’t be able to follow and learn more about loyal commenters even if they’re willing to share that information. Like I said earlier, it can streamline the experience and definitely has some uses, but use this capability with caution.
It works.. Thanks … Great Works
Hi,
A quick question. We have set up a blog for our travel. Our friends have reported that when they reply to or leave a comment the box are already completed with the persons name and email from the previous comment. Essentially this means people’s enails are getting seen and shared which we do not want. The comments box also says that this won’t happen however we can’t seem to figure out what is going on. It would be great if you could point us in the right direction. Thanks , Kel