[Resolved] How to change comment form placeholders?

Home Forums Support [Resolved] How to change comment form placeholders?

Home Forums Support How to change comment form placeholders?

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #542229
    Paritosh Negi

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

    Waiting for your reply… Thank you πŸ™‚

    GeneratePress 2.0.2
    GP Premium 1.6.2
    #542614
    Tom
    Lead Developer
    Lead Developer

    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.

    #542799
    Paritosh Negi

    Thank you Tom… it worked!

    #543082
    Tom
    Lead Developer
    Lead Developer
    #605769
    Randy

    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.

    #606180
    Tom
    Lead Developer
    Lead Developer

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

    #606220
    Randy

    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 );
    }
    #606473
    Tom
    Lead Developer
    Lead Developer

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

    #606481
    Randy

    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).

    #606482
    Tom
    Lead Developer
    Lead Developer

    What are the contents of the tu_disable_comment_url() function?

    #606483
    Randy
    function tu_disable_comment_url($fields) {
        unset($fields['url']);
        return $fields;
    }
    #606484
    Tom
    Lead Developer
    Lead Developer

    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 );
    }
    #606495
    Randy

    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?

    #606895
    Tom
    Lead Developer
    Lead Developer

    You’re welcome!

    She’s 2 now πŸ™‚

    #607013
    Randy

    Awesome.

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.