[Resolved] Remove Placeholder text from Comments Form

Home Forums Support Remove Placeholder text from Comments Form

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1338530
    Alicia

    Hi!

    I’d love to remove placeholder text from Comment form. I’ve got the labels visible but can’t seem to remove the placeholder text.

    I even followed this solution and tweaked it to see if I could get it to work. But, no dice.

    #1338713
    David
    Staff
    Customer Support

    Hi there,

    can you share the code you used to remove the placeholders ?

    #1339510
    Alicia

    Hi!

    I went back and futzed with the code a bit and got the placeholders for Author and Email to disappear. Now, I’m needing the Website URL placeholder to disappear. I’m not sure if the filter I’m using is accurate even for Author and Email, since the solution was for a specific scenario.

    Here’s my code:

    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields', 20 );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />';
    
        $fields['email'] = '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        return $fields;
    }
    #1339872
    David
    Staff
    Customer Support

    You can include this in your function:

    unset( $fields['url'] );

    Add it before the return $fields;

    #1343208
    Alicia

    Hi David,
    I actually want to keep the Website field, I just want to get rid of the placeholder text. The code I grabbed doesn’t have the website field included, so I’m not sure of the proper syntax.

    #1343360
    David
    Staff
    Customer Support

    Oops sorry … try this:

    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields', 20 );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />';
    
        $fields['email'] = '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        $fields['url'] = '<label for="url" class="screen-reader-text">' . esc_html__( 'URL', 'generatepress' ) . '</label><input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />';
    
        return $fields;
    }
    #1347562
    Alicia

    Hi David!!

    Awesome sauce. That’s just what I needed!

    Thanks!

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