How to Allow Users to Post Anonymous Comments in WordPress


Recently one of our users asked if it was possible to allow anonymous comments in WordPress. By default, users cannot leave comments in WordPress without providing a name and email address in the comment form. In this article, we will show you how to allow users to post anonymous comments in WordPress. We will also show you how to hide name and email fields from WordPress comment form.

Pseudonym: The Ideal Solution

The best way to allow anonymous comments in WordPress while limiting comment spam is by encouraging users to use a pseudonym or a nickname instead of their real name.

This allows you to build a community while still allowing users to be anonymous. Users will still have to provide an email address, but most folks who want to leave anonymous comments have separate emails for this anyways.

You can communicate this in your comments policy and place a prominent link to it above your comment form.

While this is the ideal solution, and the only one that we recommend, there are other solutions to allow further anonymity. However the more anonymity you add, the higher your spam will be.

Making Name and Email Optional

The next layer of anonymity you can add is make the name and email field completely optional. No nicknames or anything. If a user submits just a comment without name and email, it will go through. Let’s take a look at how to make name and email fields completely optional.

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.

Disable name and email address as required fields in WordPress comment form

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.

  function wpb_alter_comment_form_fields($fields) {    // Modify Name Field and show that it's Optional   $fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . __( 'Name (Optional)' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .  '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';    // Modify Email Field and show that it's Optional  $fields['email'] = '<p class="comment-form-email"><label for="email">' . __( 'Email (Optional)', 'twentythirteen' ) . '</label> ' .        ( $req ? '<span class="required">*</span>' : '' ) .        '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .        '" size="30"' . $aria_req . ' /></p>';     // This line removes the website URL from comment form. 	    	  $fields['url'] = '';        return $fields;  }  add_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:

Comment form showing name and email address as optional fields in WordPress

How to Completely Remove Name and Email From Comment Form

For those users who want to remove name and email fields from comment form, here is the little piece of code that you need to paste in your theme’s functions.php file or a site specific plugin.

  function wpb_alter_comment_form_fields($fields) {      unset($fields['author']);      unset($fields['email']);      unset($fields['url']);      return $fields;  }  add_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:

  <?php   comment_form(array(  'comment_notes_before' => '<p class="comment-notes">' . __( 'No name or email address required.' ) . ( $req ? $required_text : '' ) . '</p>'      ));  ?>

If you can not 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.

  .comment-notes {  display:none;  }

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

Comment form without name, email and URL fields

Word of Caution about Anonymous Comments

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.

We hope this article helped you with your decision of allowing anonymous comments in WordPress. We covered a lot of comment form styling, so if you want to learn more, then check out our guide on styling your comments layout.

If you like this article, then please follow us on Google+ and YouTube.

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.