- This topic has 10 replies, 2 voices, and was last updated 3 years, 6 months ago by Leo.
-
AuthorPosts
-
October 28, 2020 at 8:46 am #1508128George
Is there a function to add a placeholder in the comment form textarea field?
The following code doesn’t work:
add_filter( 'comment_form_defaults', 'gm_textarea_placeholder' ); function gm_textarea_placeholder( $fields ) { $fields['comment_field'] = str_replace( '<textarea', '<textarea placeholder="Comment"', $fields['comment_field'] ); return $fields; }
October 28, 2020 at 9:36 am #1508198LeoStaffCustomer SupportHi George,
The comment is field is handled by WordPress and I found this article that might help?
https://pupungbp.com/add-placeholder-to-your-comment-form-in-wordpress/October 28, 2020 at 9:37 am #1508199GeorgeYes, Leo, I have tried everything, nothing works!
October 28, 2020 at 9:41 am #1508204LeoStaffCustomer SupportAny chance you can check with WordPress’ support team first and see if they can provide any quick pointers?
October 28, 2020 at 9:43 am #1508206GeorgeOh really? Not hoping to get a reply any time soon from them. Damn, didn’t think it was that complicated! Maybe somehow GP overrides those settings? I have tried a lot of code that should work but it doesn’t.
October 28, 2020 at 9:45 am #1508209LeoStaffCustomer SupportI don’t think so but definitely could be wrong π
Did you test if the same code works in a twenty series WP theme?
Let me know π
October 28, 2020 at 9:48 am #1508212GeorgeDoesn’t work on a default theme, either. The
yourdomain
needs to be placed bygeneratepress
, right?October 28, 2020 at 9:57 am #1508222GeorgeI have also tried this, no luck!
https://www.billerickson.net/code/use-placeholders-instead-of-labels-in-comment-form/October 28, 2020 at 9:59 am #1508224LeoStaffCustomer SupportWhat about 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="PLACE HOLDER TEXT HERE" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>', esc_html__( 'Comment', 'generatepress' ) ); return $defaults; }, 20 );
October 28, 2020 at 10:02 am #1508233GeorgeYes, that’s it, it was the priority!
This one also works now:
function placeholder_comment_form_field($fields) { $replace_comment = __('Your Comment', 'generatepress'); $fields['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" placeholder="'.$replace_comment.'" aria-required="true"></textarea></p>'; return $fields; } add_filter( 'comment_form_defaults', 'placeholder_comment_form_field', 20 );
Leo, you are a savior, thank you!
October 28, 2020 at 10:06 am #1508237LeoStaffCustomer SupportNo problem π
-
AuthorPosts
- You must be logged in to reply to this topic.