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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

After 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