Site logo

Archived topic

How to change comment form placeholders?

18 replies · Started by Paritosh Negi on April 5, 2018

Viewing posts 1–15 of 19

Hi! How can I change the placeholder of Name, E-mail and URL in comment form?

Waiting for your reply... Thank you :)

Hi there,

Give this a shot:

add_filter( 'comment_form_default_fields', 'tu_adjust_comment_form_fields' );
function tu_adjust_comment_form_fields( $fields ) {
    return array(
        'author' => '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Name', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />',
        'email' => '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Email', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />',
        'url' => '<label for="url" class="screen-reader-text">' . esc_html__( 'Website', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Website', 'generatepress' ) . '" id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />',
    );
}

Adjust the placeholder value.

Thank you Tom... it worked!

You're welcome :)

Like this? (just one line to simplify):

'author' => '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'First Name and Location', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />',

...because that's not working for me.

Can you include your full function? Be sure to highlight the code and click the "code" button in the editor toolbar.

Certainly. I have this in functions.php (child theme):

//Change form placeholder
add_filter( 'comment_form_default_fields', 'tu_adjust_comment_form_fields' );
function tu_adjust_comment_form_fields( $fields ) {
    return array(
        'author' => '<label for="author" class="screen-reader-text">' . esc_html__( 'First Name and Location', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'First Name and location', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />',
        'email' => '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Email', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />',
        'url' => '<label for="url" class="screen-reader-text">' . esc_html__( 'Website', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Website', 'generatepress' ) . '" id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />',
    );
}

//Kill URL in comment form
add_action( 'after_setup_theme', 'tu_add_comment_url_filter' );
function tu_add_comment_url_filter() {
    add_filter( 'comment_form_default_fields', 'tu_disable_comment_url', 20 );
}

And what are you trying to do? Remove the URL field?

Already have the URL removed; I included that part of the function in case there was any conflict causing the problem. Just trying to change the placeholder text as shown. Isn't doing anything.

You can look at https://dev.thisistrue.com (which will go away as soon as this issue is resolved -- I'm otherwise ready to move it to production, my largest site to move from Canvas to GP).

What are the contents of the tu_disable_comment_url() function?

function tu_disable_comment_url($fields) {
    unset($fields['url']);
    return $fields;
}

Try this as your PHP:

function tu_adjust_comment_form_fields( $fields ) {
    return array(
        'author' => '<label for="author" class="screen-reader-text">' . esc_html__( 'First Name and Location', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'First Name and location', 'generatepress' ) . ' *" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" />',
        'email' => '<label for="email" class="screen-reader-text">' . esc_html__( 'Email', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Email', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />',
    );
}

//Kill URL in comment form
add_action( 'after_setup_theme', 'tu_add_comment_url_filter' );
function tu_add_comment_url_filter() {
    add_filter( 'comment_form_default_fields', 'tu_adjust_comment_form_fields', 20 );
}

Whew! I'll have to look really carefully at what changed, but that did it.

Thanks much.

P.S.: How old is your baby (in the photo) now?

You're welcome!

She's 2 now :)

Awesome.

This archived topic is closed to new replies.