- This topic has 10 replies, 2 voices, and was last updated 1 year, 8 months ago by
Leo.
-
AuthorPosts
-
October 28, 2020 at 8:46 am #1508128
George
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 #1508198Leo
StaffCustomer 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/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 28, 2020 at 9:37 am #1508199George
Yes, Leo, I have tried everything, nothing works!
October 28, 2020 at 9:41 am #1508204Leo
StaffCustomer SupportAny chance you can check with WordPress’ support team first and see if they can provide any quick pointers?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 28, 2020 at 9:43 am #1508206George
Oh 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 #1508209Leo
StaffCustomer 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 π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 28, 2020 at 9:48 am #1508212George
Doesn’t work on a default theme, either. The
yourdomain
needs to be placed bygeneratepress
, right?October 28, 2020 at 9:57 am #1508222George
I 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 #1508224Leo
StaffCustomer 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 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 28, 2020 at 10:02 am #1508233George
Yes, 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 #1508237Leo
StaffCustomer SupportNo problem π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.