• Resolved smellpress

    (@smellpress)


    I have made the name and email fields optional in the WordPress settings, and would like to remove the asterisks from the fields because they give a misleading impression that the fields are required.

    I have copied comments.php into my child theme and have successfully modified some aspects of it, but cannot manage to change placeholder="Name *" and placeholder="Email *", even when when wrapping comment_form($args) in str_replace()! Attempting to replace the HTML with $fields['author'] = "myMarkupHere" ceases to do anything, though I can use that for fictional fields – a possible workaround?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    You shouldn’t need to overwrite comments.php.

    Instead, add this function:

    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 );
    Thread Starter smellpress

    (@smellpress)

    Cheers, it works!

    • This reply was modified 4 years, 7 months ago by smellpress.
    Theme Author Tom

    (@edge22)

    Glad I could help! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changing comment fields to remove asterisks?’ is closed to new replies.