admin管理员组文章数量:1124777
Goal:
I need to hide/disable the text-area comment field, and only display author field. I've succeeded in doing this with the code below.
Problem:
Text-area comment input is hidden, but is still required, meaning when you enter your name and hit Sign, this error is shown: Error: Please type your comment text.
from url .php
Question:
How can I make the comment input field 'comment' un-required?
Environment:
- www.theplaydesignmanifesto (comment form at bottom)
- Wordpress 6.2
- Child theme of GeneratePress
Current code
As you can see, I attempt to unset the 'comment' field and not display it afterwards.
I've added this code in functions.php
add_filter( 'comment_form_fields', 'custom_comment_field' );
function custom_comment_field( $fields ) {
// What fields you want to control.
$comment_field = $fields['author'];
$comment_field = $fields['comment'];
// The fields you want to unset (remove).
unset($fields['author']);
unset($fields['comment']);
// Display the fields to your own taste.
// The order in which you place them will determine in what order they are displayed.
$fields['author'] = '<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label><input type="text" id="author" name="author" required="required" placeholder="Name"></p>';
return $fields;
}
Code source: /
Previously answered threads like this I've tried
How to make comment text field un-required?
Goal:
I need to hide/disable the text-area comment field, and only display author field. I've succeeded in doing this with the code below.
Problem:
Text-area comment input is hidden, but is still required, meaning when you enter your name and hit Sign, this error is shown: Error: Please type your comment text.
from url https://theplaydesignmanifesto.org/wp-comments-post.php
Question:
How can I make the comment input field 'comment' un-required?
Environment:
- www.theplaydesignmanifesto.org (comment form at bottom)
- Wordpress 6.2
- Child theme of GeneratePress
Current code
As you can see, I attempt to unset the 'comment' field and not display it afterwards.
I've added this code in functions.php
add_filter( 'comment_form_fields', 'custom_comment_field' );
function custom_comment_field( $fields ) {
// What fields you want to control.
$comment_field = $fields['author'];
$comment_field = $fields['comment'];
// The fields you want to unset (remove).
unset($fields['author']);
unset($fields['comment']);
// Display the fields to your own taste.
// The order in which you place them will determine in what order they are displayed.
$fields['author'] = '<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label><input type="text" id="author" name="author" required="required" placeholder="Name"></p>';
return $fields;
}
Code source: https://developer.wordpress.org/reference/hooks/comment_form_fields/
Previously answered threads like this I've tried
How to make comment text field un-required?
Share Improve this question edited May 12, 2023 at 11:12 Unloving1507 asked May 12, 2023 at 11:09 Unloving1507Unloving1507 112 bronze badges1 Answer
Reset to default 1After a lot of trial-and-error from other questions and sources, I discovered the allow_empty_comment
filter.
This simple filter allowed me to submit comments without filling in the actual "comment" box.
add_filter( 'allow_empty_comment', '__return_true' );
More info here
本文标签: Make comment textarea input unrequired
版权声明:本文标题:Make comment textarea input un-required 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736629483a1945745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论