如果您的网站显示评论隐私复选框,则无需进一步阅读。但是,如果您的网站上没有显示评论复选框,那么您需要继续阅读,我们将向您展示如何在WordPress中添加评论隐私复选框。
如果您的当前主题或WordPress有更新,请继续安装。接下来,检查您网站的评论表单,看看更新是否添加了评论隐私复选框。
如果您的主题和WordPress都是最新的,并且您仍然看不到评论隐私复选框,那么这意味着您的WordPress主题将覆盖默认的WordPress评论表单。
您可以通过打开支持服务单让您的主题作者解决此问题。您也可以尝试自己修复它,直到您的主题作者发布更新。
您可以通过两种方式将注释隐私复选框添加到WordPress主题中。我们将向您展示这两种方法,您可以尝试一种适合您的方法。
这两种方法都要求您将代码添加到WordPress主题文件中。如果您之前没有这样做,请参阅我们的指南,了解如何在WordPress中复制和粘贴代码。
方法1.在主题的评论表单中添加评论隐私复选框
建议使用此方法,因为它会尝试保护主题的注释表单样式和布局。
首先,您需要找到用于覆盖默认WordPress评论表单的代码。通常,您可以在主题文件夹的comments.php或functions.php文件中找到它。
您将使用'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); ?> |
方法2.使用WordPress默认值替换主题的注释表单
此方法只是使用默认的WordPress评论表单替换主题的评论表单。使用此方法可能会影响评论表单的外观,您可能必须使用自定义CSS来设置评论表单的样式。
编辑主题的comments.php文件并查找具有该comment_form()功能的行。您的主题将在其中包含已定义的参数,函数或模板,以加载主题的自定义注释表单。您的comment_form行看起来像这样:
|
1 |
<?php comment_form( custom_comment_form_function() ); ?> |
|
1 |
<?php comment_form(); ?> |