close
name-email-optional

Many site owners want to know that is it possible to allow anonymous comments in . Users cannot leave a comment in WordPress unless they provide a name and email address in the comments form. This article will explain allow users to leave comments anonymously.

Pseudonym: The Ideal Solution

Best way to allow users to comment anonymously while limiting comment spam is by using nickname instead of their real name.

This allows you to build a community while still allowing users to comment. Users will still have to provide an email address though so we recommend a separate email address for this purpose.

Making Name and Email Optional

Next you can do is make the name and email address completely optional. If a user submits a comment without a name and email address it will go through.

First thing you need to do is go to Settings » Discussion and uncheck the box next to ‘Comment author must fill out name and e-mail’ option. Now you need to save your changes, and your site will be ready to accept comments without name and email address.

anonymous-comments

Simply removing this checkbox wouldn’t tell your users that they can leave comments without providing a name or email address. You may want to communicate this by showing that name and email fields are optional. We also suggest removing the website URL field to discourage spam. To do this, you need to modify your comment form. Simply copy and paste the following code in your theme’s functions.php file or in a site-specific plugin.

01function wpb_alter_comment_form_fields($fields) {

 

02 

 

03// Modify Name Field and show that it’s Optional

 

04$fields[‘author’] = ‘<p class=”comment-form-author”>’ . ‘<label for=”author”>’ . __( ‘Name (Optional)’ ) . ‘</label> ‘ . ( $req? ‘<span class=”required”>*</span>’ : ” ) .

 

05‘<input id=”author” name=”author” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author’] ) . ‘” size=”30″‘ .$aria_req . ‘ /></p>’;

 

06 

 

07// Modify Email Field and show that it’s Optional

 

08$fields[’email’] = ‘<p class=”comment-form-email”><label for=”email”>’ . __( ‘Email (Optional)’, ‘twentythirteen’ ) .'</label> ‘ .

 

09      ( $req ? ‘<span class=”required”>*</span>’ : ” ) .

 

10      ‘<input id=”email” name=”email” type=”text” value=”‘ . esc_attr(  $commenter[‘comment_author_email’] ) .

 

11      ‘” size=”30″‘ . $aria_req . ‘ /></p>’;

 

12 

 

13// This line removes the website URL from comment form.

 

14      $fields[‘url’] = ”;

 

15 

 

16    return $fields;

 

17}

 

18add_filter(‘comment_form_default_fields’,’wpb_alter_comment_form_fields’);

 

This code simply adds (Optional) next to name and email fields in your comment form. It also removes the website URL field from the comment form. If you want to keep the website URL field, then remove that line of code. Here is how your comment form would look like:

name-email-optional

How to Completely Remove Name and Email From Comment Form

If you want to remove name and email field from comment form then you need to paste the following code in your theme’s functions.php file or a site specific plugin.

1function wpb_alter_comment_form_fields($fields) {

 

2    unset($fields[‘author’]);

 

3    unset($fields[’email’]);

 

4    unset($fields[‘url’]);

 

5    return $fields;

 

6}

 

7add_filter(‘comment_form_default_fields’,’wpb_alter_comment_form_fields’);

 

If your comment form is showing Your email address will not be published text, then you can hide it by editing the your theme’s comments.php file. Locate the tag <?php comment_form ?> and replace it with this code:

1<?php

 

2comment_form(array(

 

3‘comment_notes_before’ => ‘<p class=”comment-notes”>’ . __( ‘No name or email address required.’ ) . ( $req ? $required_text :” ) . ‘</p>’

 

4    ));

 

5?>

 

If you cannot locate the comment_form, then you can still hide this text by adding this CSS into your theme or child theme‘s style.css file.

1.comment-notes {

 

2display:none;

 

3}

 

This is how your comment form will look like without name, email, and website URL fields:

noname-email-comment

* Please note that without name and email address as required fields, your comment form will attract a significantly high number of spam comments. While Akismet and Sucuri may block some bad IPs, we highly recommend that you put a captcha verification to prevent some of that.

 

Tags : wordpressWordPress how to
Nooruddin Ahmed

The author Nooruddin Ahmed

An avid football fan. Lives for the weekend game.Aviation enthusiast. Believes in letting bygones be bygones.

Leave a Response