'comment_form_default_fields'
过滤器查找代码。主题使用此过滤器来覆盖默认的WordPress评论表单。
它将以特定格式包含所有评论表单字段的行。这是一个示例代码,可以让您了解要查找的内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 |
$comments_args = array ( // change the title of send button 'label_submit' => esc_html(__( 'Post Comments' , 'themename' )), // change the title of the reply section 'title_reply' => esc_html(__( 'Leave a Comment' , 'themename' )), // redefine your own textarea (the comment body) 'comment_field' => ' <div class = "form-group" ><div class = "input-field" ><textarea class = "materialize-textarea" type= "text" rows= "10" id= "textarea1" name= "comment" aria-required= "true" ></textarea></div></div>', 'fields' => apply_filters( 'comment_form_default_fields' , array ( 'author' => '' . '<div><div class="input-field">' . '<input class="validate" id="name" name="author" placeholder="' . esc_attr(__( 'Name' , 'themename' )) . '" type="text" value="' . esc_attr( $commenter [ 'comment_author' ] ) . '" size="30"' . $aria_req . ' /></div></div>' , 'email' => '' . '<div><div class="input-field">' . '<input class="validate" id="email" name="email" placeholder="' . esc_attr(__( 'Email' , 'themename' )) . '" type="email" value="' . esc_attr( $commenter [ 'comment_author_email' ] ) . '" size="30"' . $aria_req . ' /></div></div>' , 'url' => '' . '<div class="form-group">' . '<div><div class="input-field"><input class="validate" placeholder="' . esc_attr(__( 'Website' , 'themename' )) . '" id="url" name="url" type="text" value="' . esc_attr( $commenter [ 'comment_author_url' ] ) . '" size="30" /></div></div>' , ) ), ); comment_form( $comments_args ); ?> |
comment_form_default_fields
过滤器用于修改作者,电子邮件和URL字段。在数组内部,它使用以下格式显示每个字段:
1
2 |
'fieldname' => 'HTML code to display the field' , 'anotherfield' => 'HTML code to display the field' , |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 |
$comments_args = array ( // change the title of send button 'label_submit' => esc_html(__( 'Post Comments' , 'themename' )), // change the title of the reply section 'title_reply' => esc_html(__( 'Leave a Comment' , 'themename' )), // redefine your own textarea (the comment body) 'comment_field' => ' <div class = "form-group" ><div class = "input-field" ><textarea class = "materialize-textarea" type= "text" rows= "10" id= "textarea1" name= "comment" aria-required= "true" ></textarea></div></div>', 'fields' => apply_filters( 'comment_form_default_fields' , array ( 'author' => '' . '<div><div class="input-field">' . '<input class="validate" id="name" name="author" placeholder="' . esc_attr(__( 'Name' , 'themename' )) . '" type="text" value="' . esc_attr( $commenter [ 'comment_author' ] ) . '" size="30"' . $aria_req . ' /></div></div>' , 'email' => '' . '<div><div class="input-field">' . '<input class="validate" id="email" name="email" placeholder="' . esc_attr(__( 'Email' , 'themename' )) . '" type="email" value="' . esc_attr( $commenter [ 'comment_author_email' ] ) . '" size="30"' . $aria_req . ' /></div></div>' , 'url' => '' . '<div class="form-group">' . '<div><div class="input-field"><input class="validate" placeholder="' . esc_attr(__( 'Website' , 'themename' )) . '" id="url" name="url" type="text" value="' . esc_attr( $commenter [ 'comment_author_url' ] ) . '" size="30" /></div></div>' , // Now we will add our new privacy checkbox optin 'cookies' => '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>' , ) ), ); comment_form( $comments_args ); ?> |
comment_form()
功能的行。您的主题将在其中包含已定义的参数,函数或模板,以加载主题的自定义注释表单。您的comment_form行看起来像这样:
1 |
<?php comment_form( custom_comment_form_function() ); ?> |
1 |
<?php comment_form(); ?> |