Archived topic
Comment - Put an optional under the Email and Website options.
5 replies · Started by James on July 18, 2020
Hi,
I have went into Settings -> Discussion and uncheck "Comment Author must filled out Name and Email".
There's still an Asterisk * beside both Name and Email but I have checked and filled out a dummy comment without inputting email and it works.
How can i remove the Asterisk * and replace it with an "(optional)" word instead?
Thanks.
Hi there,
Tom provides a snippet here:
Thanks David.
That link worked but it just made the Asterisk * disappear. I am looking to add the "(Optional)" word beside Email & Website.
Thanks.
try this:
add_filter( 'comment_form_default_fields', function( $fields ) {
$commenter = wp_get_current_commenter();
$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 optional', 'generatepress' ),
esc_attr( $commenter['comment_author_email'] )
);
$fields['url'] = sprintf(
'<label for="url" class="screen-reader-text">%1$s</label><input placeholder="%1$s" id="url" name="url" type="url" value="%2$s" size="30" />',
esc_html__( 'Website optional', 'generatepress' ),
esc_attr( $commenter['comment_author_url'] )
);
return $fields;
}, 20 );
Thanks David, this was what I needed.
Glad to be of help