- This topic has 15 replies, 3 voices, and was last updated 4 years, 7 months ago by Tom.
-
AuthorPosts
-
August 14, 2019 at 4:56 pm #984430Jim
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.August 15, 2019 at 9:06 am #984975TomLead DeveloperLead DeveloperHi 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?
August 15, 2019 at 12:32 pm #985109Jim1. 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).August 15, 2019 at 5:40 pm #985284TomLead DeveloperLead DeveloperThose fields should have placeholders by default. Do you have any other functions that would target the comment fields?
August 15, 2019 at 5:58 pm #985298JimI 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.
August 16, 2019 at 10:04 am #985931TomLead DeveloperLead DeveloperSounds good 🙂
August 17, 2019 at 1:36 am #986312JimHi 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.
August 17, 2019 at 3:06 am #986355DavidStaffCustomer SupportHi there,
Tom provides a filter for that here:
https://generatepress.com/forums/topic/how-to-change-comment-form-placeholders/#post-542614
August 17, 2019 at 11:18 am #986715JimHi 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" />', ); }
August 17, 2019 at 11:40 am #986731DavidStaffCustomer SupportI just checked your site and i can see the new placeholders. Try clearing browser caches.
August 17, 2019 at 11:43 am #986737JimIt’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 ); }
August 17, 2019 at 4:55 pm #986852TomLead DeveloperLead DeveloperInstead 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; }
August 17, 2019 at 7:31 pm #986902JimHi 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 ); }
August 18, 2019 at 9:58 am #987372TomLead DeveloperLead DeveloperIs 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; }
August 18, 2019 at 8:08 pm #987549JimThat worked! Thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.