Site logo

Archived topic

Remove Placeholder text from Comments Form

7 replies · Started by Alicia on June 23, 2020

Viewing posts 1–8 of 8

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.

Hi there,

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

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;
}

You can include this in your function:

unset( $fields['url'] );

Add it before the return $fields;

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.

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;
}

Hi David!!

Awesome sauce. That's just what I needed!

Thanks!

Glad to be of help

This archived topic is closed to new replies.