跳到主要内容

您是否要在WordPress中添加评论隐私选项复选框?欧盟新的GDPR法律要求存储用户个人信息的明确同意。如果您在网站上启用了评论,则需要添加评论隐私复选框以符合新法律。在本文中,我们将向您展示如何在WordPress中添加GDPR评论隐私选择加入复选框。

何时以及为何在WordPress中添加评论隐私优化复选框?

最近,一项称为GDPR(通用数据保护条例)的新欧盟法律已生效。该法律的目的是使欧盟公民能够控制其个人数据,并改变全球组织的数据隐私方法。

要了解更多信息,请参阅我们的WordPress和GDPR合规性最终指南,该指南以通俗的英语回答您的所有问题。

WordPress最近在最新的4.9.6版本中解决了GDPR合规性问题。如果尚未更新,则需要立即更新到最新的WordPress版本

WordPress存储和使用个人信息的方式之一是在评论表单中。当用户在您的网站上发表评论时,其名称,电子邮件地址和网站信息将存储在浏览器cookie中。此cookie使WordPress可以在下次访问时在评论表单中自动填写用户的信息。

使用WordPress 4.9.6时,默认的WordPress注释表单现在将显示“注释隐私选择加入”复选框。现在,使用默认WordPress注释表单的所有WordPress主题将自动显示此复选框。

如果您的网站显示“评论隐私”复选框,则无需进一步阅读。但是,如果您的网站上未显示注释复选框,则您需要继续阅读,我们将向您展示如何在WordPress中添加注释隐私复选框。

如何在wordpress中创建符合gdpr的表格
如何在wordpress中创建符合gdpr的表格

在WordPress中添加评论隐私优化复选框

首先,您需要确保使用的是最新版本的WordPress和您的主题。只需转到仪表板»更新页面以检查更新。

如果您当前的主题或WordPress有可用的更新,请继续进行安装。接下来,检查您网站的评论表单,以查看更新是否添加了评论隐私复选框。

如果您的主题和WordPress都是最新的,并且您仍然看不到评论隐私复选框,则意味着您的WordPress主题将覆盖默认的WordPress评论形式。

您可以通过打开支持通知单要求主题作者解决此问题。您也可以尝试自己修复它,直到主题作者发布更新为止。

您可以通过两种方式将注释隐私复选框添加到WordPress主题。我们将向您展示这两种方法,您可以尝试一种适合您的方法。

这两种方法都要求您将代码添加到WordPress主题文件中。如果您以前没有做过,请参阅有关如何在WordPress中复制和粘贴代码的指南。

方法1.将注释隐私复选框添加到主题的注释表单

建议使用此方法,因为它会尝试保护主题的注释表单样式和布局。

首先,您需要找到用于覆盖默认WordPress注释表单的代码。通常,您可以在主题文件夹中的comment.php或functions.php文件中找到它。

您将使用’comment_form_default_fields’ 过滤器查找代码。主题使用此过滤器来覆盖默认的WordPress评论表单。

它将以特定格式在所有评论表单字段中显示行。这是一个示例代码,可让您大致了解所需的内容:

$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字段。在数组内部,它使用以下格式显示每个字段:

‘fieldname’=> ‘HTML code to display the field’, ‘anotherfield’=> ‘HTML code to display the field’,

我们将在最后添加评论隐私选项复选框。这是我们的代码现在的样子:

$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来设置注释表单的样式

编辑主题的comment.php文件,然后查找包含该comment_form()功能的行。您的主题中将具有定义的参数,函数或模板,以加载​​主题的自定义评论表单。您的comment_form行将如下所示:

<?php comment_form( custom_comment_form_function() ); ?>

您将需要用以下行替换它:

<?php comment_form(); ?>

不要忘记保存更改并访问您的网站。现在,您将看到带有注释隐私选项复选框的默认WordPress注释表单。

我们希望本文能帮助您学习如何在WordPress中添加GDPR评论隐私选择复选框。您可能还想查看有关在WordPress博客文章获得更多评论的提示。

回到顶部