Site logo

Archived topic

Comment fields placeholders

11 replies · Started by pancakebg on May 24, 2018

Viewing posts 1–12 of 12

Hey guys, can you help me to change the text on the placeholders in the comments section?

I need to replace the name, e-mail and if possible to remove the website field.

Also i would like to know if i can change the text on this: Save my name, email, and website in this browser for the next time I comment.

I already found this posted by Tom but when i add it to the child theme function.php and replace the fields - nothing happens.

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" />',
    );
}

Thank you! :)

Hi there,

You can try something like this:

add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields' );
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 placeholder="' . esc_attr__( 'Name', 'generatepress' ) . ' *" 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 placeholder="' . esc_attr__( 'Email', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';

    $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';

    $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">Your modified text here</label></p>';
	
    unset( $fields['url'] );

    return $fields;
}

Sadly, it does not work for me.

The placeholders did not changed.

The box with the URL still there.

However, the "Save my name, email, and website in this browser for the next time I comment." did changed but the check box goes between the "Name" and "Email" boxes on the upper row.

That's a bit hard to figure it out how to do it. ;[

Is the code still added?

I tested the same code using Code Snippets and everything worked for me.

I removed it but i will add it back so you can check it out.

Thanks! :)

Can you share the code with the changes you added to your site?

Yes, here is the code:

add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields' );
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 placeholder="' . esc_attr__( 'NEW NAME HERE', 'generatepress' ) . ' *" 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 placeholder="' . esc_attr__( 'NEW EMAIL HERE', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';

    $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';

    $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">TEXT FOR CHECKBOX HERE</label></p>';
	
    unset( $fields['url'] );

    return $fields;
}

And this is being added to your child theme?

Any other functions/changes made to template files regarding the comments area?

Maybe 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 placeholder="NEW NAME HERE *" 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 placeholder="NEW EMAIL HERE *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';

    $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';

    $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">TEXT FOR CHECKBOX HERE</label></p>';
	
    unset( $fields['url'] );

    return $fields;
}

Thanks Tom!

I have a bit of success with the last one but the check box still between the two fields

I have no problem to remove this box if you know how to do it.

For the fields i use this css:

@media (min-width: 769px) {
    .comment-form #author, 
    .comment-form #email {
        width: 48%;
        float: left;
    }
    .comment-form #email {
        float: right;
    }
    .comment-form #url {
        width: 100%;
    }
}

I also have few added filters in the function.php about the comments mainly to change the names.

The code is up and you can check the site.

Thank you!

Try this CSS:

.comment-form-cookies-consent {
    clear: both;
}

Works great, thank you!

No problem! :)

This archived topic is closed to new replies.