[Resolved] Comment box

Home Forums Support [Resolved] Comment box

Home Forums Support Comment box

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #984430
    Jim

    Hi.
    1. Is there an easier way to show the placeholder text in the comment box fields like how it is done on this website? https://www.nosegraze.com/breaking-up-with-yoast-seo/
    2. This is outside the support scope but I would appreciate your help. I noticed the specific link I shared privately shows up twice in gtmetrix waterfall and I am not sure why since it is the same link (which causes an extra HTTP request). Could you kindly comment if you know what the problem is? I haven’t discovered any other so far except this one.

    #984975
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. Try this:

    add_filter( 'comment_form_defaults', function( $defaults ) {
        $defaults['comment_field'] = sprintf(
            '<p class="comment-form-comment"><label for="comment" class="screen-reader-text">%1$s</label><textarea placeholder="Tell me what you think!" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
            esc_html__( 'Comment', 'generatepress' )
        );
    
        return $defaults;
    }, 20 );

    2. I’m not sure I’m seeing this. Which resource is loading twice?

    #985109
    Jim

    1. Thanks, but could you kindly add the name and email fields to that code?
    2. Thanks for that heads up. I figured it was a cache issue when logged in to Gtmetrix. Consider this resolved (it was the URL redirecting to itself hence showing a 301 redirect in the waterfall).

    #985284
    Tom
    Lead Developer
    Lead Developer

    Those fields should have placeholders by default. Do you have any other functions that would target the comment fields?

    #985298
    Jim

    I don’t. It seems the site I shared uses a custom function. Will try to see if I can request it from the owner. Thanks.

    #985931
    Tom
    Lead Developer
    Lead Developer

    Sounds good 🙂

    #986312
    Jim

    Hi Tom. I think the easier way is to change the placeholder text inside the comments box field. How do I do that? (Name* and Email*)? I removed the code that showed the comments field labels (which are hidden by default) coz google stopped showing accessibility errors. So now the text is inside the fields.

    #986355
    David
    Staff
    Customer Support
    #986715
    Jim

    Hi David. I tried this one but it is not working.

    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__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />',
            );
    }
    #986731
    David
    Staff
    Customer Support

    I just checked your site and i can see the new placeholders. Try clearing browser caches.

    #986737
    Jim

    It’s coz I played around with the other codes in the same support thread. The initial one did not work. Anyway, it seems the cookie consent box though has disappeared from the comments box. Here is the final code I am using.

    // Change placeholder text in the comments field name and email.
    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__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', '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 );
    }

    And here are all the codes targeting the comment form.

    // Change “Leave a Comment” in the comments box to different text.
    add_filter( 'generate_leave_comment','tu_custom_leave_comment' );
    function tu_custom_leave_comment() {
        return 'I Would Love to Hear Your Thoughts on This Article!';
    }
    // Remove ‘website’ from “Save my name, e-mail, and website in this browser for the next time I comment.”
    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields', 20 );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
        $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">Save my name and e-mail in this browser for the next time I comment.</label></p>';
        return $fields;
    }
    // Remove h3 tag on comment reply title.
    add_filter( 'comment_form_defaults', 'custom_reply_title' );
    function custom_reply_title( $defaults ){
      $defaults['title_reply_before'] = '<strong id="reply-title" class="comment-reply-title">';
      $defaults['title_reply_after'] = '</strong>';
      return $defaults;
    }
    // Show placeholder text in the comments field.
    add_filter( 'comment_form_defaults', function( $defaults ) {
        $defaults['comment_field'] = sprintf(
            '<p class="comment-form-comment"><label for="comment" class="screen-reader-text">%1$s</label><textarea placeholder="Type Your Comment Here!" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
            esc_html__( 'Comment', 'generatepress' )
        );
    
        return $defaults;
    }, 20 );
    
    // Change placeholder text in the comments field name and email.
    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__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', '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 );
    }
    #986852
    Tom
    Lead Developer
    Lead Developer

    Instead of this:

    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__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />',
        );
    }

    Try this:

    function tu_adjust_comment_form_fields( $fields ) {
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        return $fields;
    }
    #986902
    Jim

    Hi Tom. I did that but that code makes the URL field to appear. Even Using the code provided here makes the URL box appear below the cookie consent line in comments. ( I am using the code snippets plugin). Here is the full code including the one above you suggested.

    // Change “Leave a Comment” in the comments box to different text.
    add_filter( 'generate_leave_comment','tu_custom_leave_comment' );
    function tu_custom_leave_comment() {
        return 'I Would Love to Hear Your Thoughts on This Article!';
    }
    // Remove ‘website’ from “Save my name, e-mail, and website in this browser for the next time I comment.”
    add_filter( 'comment_form_default_fields', 'tu_filter_comment_fields', 20 );
    function tu_filter_comment_fields( $fields ) {
        $commenter = wp_get_current_commenter();
        $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">Save my name and e-mail in this browser for the next time I comment.</label></p>';
        return $fields;
    }
    // Remove h3 tag on comment reply title.
    add_filter( 'comment_form_defaults', 'custom_reply_title' );
    function custom_reply_title( $defaults ){
      $defaults['title_reply_before'] = '<strong id="reply-title" class="comment-reply-title">';
      $defaults['title_reply_after'] = '</strong>';
      return $defaults;
    }
    // Show placeholder text in the comments field.
    add_filter( 'comment_form_defaults', function( $defaults ) {
        $defaults['comment_field'] = sprintf(
            '<p class="comment-form-comment"><label for="comment" class="screen-reader-text">%1$s</label><textarea placeholder="Type Your Comment Here!" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
            esc_html__( 'Comment', 'generatepress' )
        );
    
        return $defaults;
    }, 20 );
    
    // Change placeholder text in the comments field name and email.
    function tu_adjust_comment_form_fields( $fields ) {
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        return $fields;
    }
    //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 );
    }
    #987372
    Tom
    Lead Developer
    Lead Developer

    Is that the only issue now? If so, we should be able to remove it like this:

    function tu_adjust_comment_form_fields( $fields ) {
        $fields['author'] = '<label for="author" class="screen-reader-text">' . esc_html__( 'Name', 'generatepress' ) . '</label><input placeholder="' . esc_attr__( 'Your Name e.g Mark Odoi', '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__( 'Your Email e.g mark@gmail.com', 'generatepress' ) . ' *" id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" />';
    
        unset( $fields['url'] );
    
        return $fields;
    }
    #987549
    Jim

    That worked! Thanks.

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