[Resolved] Comment – Put an optional under the Email and Website options.

Home Forums Support Comment – Put an optional under the Email and Website options.

  • This topic has 5 replies, 2 voices, and was last updated 2 months ago by David.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1367584
    James

    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.

    View post on imgur.com

    #1367625
    David
    Staff
    Customer Support
    #1367639
    James

    Thanks David.

    That link worked but it just made the Asterisk * disappear. I am looking to add the “(Optional)” word beside Email & Website.

    Thanks.

    #1367659
    David
    Staff
    Customer Support

    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 );
    #1367962
    James

    Thanks David, this was what I needed.

    #1368110
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.