Remove the Email Field From Comments
Lets visitors comment with just a name, for communities where asking for an email address puts people off.
Opens WPIDE on
Code
add_filter( 'comment_form_default_fields', function ( $fields ) {
unset( $fields['email'] );
return $fields;
} );
// WordPress would otherwise insist on both name and email.
add_filter( 'pre_option_require_name_email', function () {
return '0';
} );
add_filter( 'preprocess_comment', function ( $commentdata ) {
$type = isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '';
if ( ! is_user_logged_in() && ( '' === $type || 'comment' === $type ) && '' === trim( (string) $commentdata['comment_author'] ) ) {
wp_die( 'Please enter your name.', 'Name required', array( 'response' => 400, 'back_link' => true ) );
}
return $commentdata;
} );
Notes
Without email addresses, Gravatars, reply notifications and some spam filters work less well.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.