Site logo

Archived topic

Comment form required fields to anonymous posting

5 replies · Started by Rogi on April 21, 2020

Viewing posts 1–6 of 6

Hi guys.

I want anonymous comments to be posted on my blog.
In the discussion settings, I unchecked the option to require filling in name and email.
But the required field asterisk still appears in the comment form.

Thanks in advance.

Hi there,

add this PHP Snippet to your site:

add_action( 'after_setup_theme', 'tu_add_comment_url_filter' );
function tu_add_comment_url_filter() {
    add_filter( 'comment_form_default_fields', 'tu_disable_comment_url', 20 );
}

function tu_disable_comment_url($fields) {
    unset($fields['url']);
    unset($fields['email']);
    unset($fields['name']);
    return $fields;
}

https://docs.generatepress.com/article/remove-e-mail-and-url-field-from-comment-form/

Hi David,

First, thanks for the quick response.
I don't want to remove the url and email fields.
I just want the required field asterisk not to appear (in the name and e-mail fields).
This code that you recommended removed the URL and Email fields...

Thanks.

Hi there,

Try this instead:

add_filter( 'comment_form_default_fields', function( $fields ) {
	$commenter = wp_get_current_commenter();

	$fields['author'] = sprintf(
		'<label for="author" class="screen-reader-text">%1$s</label><input placeholder="%1$s" id="author" name="author" type="text" value="%2$s" size="30" />',
		esc_html__( 'Name', 'generatepress' ),
		esc_attr( $commenter['comment_author'] )
	);

	$fields['email'] = sprintf(
		'<label for="email" class="screen-reader-text">%1$s</label><input placeholder="%1$s" id="email" name="email" type="email" value="%2$s" size="30" />',
		esc_html__( 'Email', 'generatepress' ),
		esc_attr( $commenter['comment_author_email'] )
	);

	return $fields;
}, 20 );

Tom,

Now it worked!

Thank you very much for your help!

Igor

You're welcome :)

This archived topic is closed to new replies.