comment_form_fields
最后更新于:2021-11-26 03:02:20
apply_filters( ‘comment_form_fields’, array $comment_fields )
Filters the comment form fields, including the textarea.
参数
- $comment_fields
-
(array)
The comment fields.
源文件
文件: gc-includes/comment-template.php
/** * Move the comment text field to the bottom. * * @see https://docs.gechiui.com/hooks/comment_form_fields/ * @param array $fields The comment fields.. * @return array */ function prefix_move_comment_field_to_bottom( $fields ) { $comment_field = $fields['comment']; unset( $fields['comment'] ); $fields['comment'] = $comment_field; return $fields; } add_filter( 'comment_form_fields', 'prefix_move_comment_field_to_bottom', 10, 1 );
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['email']; $comment_field = $fields['comment']; $comment_field = $fields['cookies']; // The fields you want to unset (remove). unset($fields['author']); unset($fields['email']); unset($fields['url']); unset($fields['comment']); unset($fields['cookies']); // 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" require="required" placeholder="Name"></p>'; $fields['email'] = '<p class="comment-form-email"><label for="email">Email <span class="required">*</span></label><input type="text" id="email" name="email" require="required" placeholder="Email"></p>'; $fields['comment'] = '<p class="comment-form-comment"><label for="comment">Comment <span class="required">*</span></label><textarea id="comment" name="comment" required="required" placeholder="Comment"></textarea></p>'; $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="gc-comment-cookies-consent" name="gc-comment-cookies-consent" type="checkbox" value="yes"><label for="gc-comment-cookies-consent">Save details for future comments?</label></p>'; return $fields; }