Would you like to add a privacy checkbox for comments on WordPress? The new GDPR law of the European Union requires explicit consent for the storage of the user's personal information. If you have enabled comments on your website, you must add a comment privacy check box to comply with the new law. In this article, we are going to show you how to add an option to enable GDPR comment privacy on WordPress.

 

how to add a privacy option on WOrdPress.png

When and why add an optional privacy checkbox on the comments?

Recently, a new European Union law called GDPR (the General Data Protection Regulation) came into force. The purpose of this law is to give EU citizens control over their personal data and to change the approach to data privacy of organizations around the world.

WordPress recently addressed GDPR compliance in the latest version 4.9.6. If you have not updated yet, you should immediately update the latest version of WordPress .

One of the ways WordPress stores and uses personal information is in the online form of comment. When a user leaves a comment on your website, their name, email address and website are stored in a browser cookie. This cookie allows WordPress to automatically populate user information into the online form comment on their next visit.

With WordPress 4.9.6, the online form WordPress comment box by default will now display a privacy comment checkbox. All the WordPress themes who use the default WordPress comment form will automatically show this checkbox.

privacy checkbox wordpress gdpr.png

If your site displays the comment privacy checkbox, you don't need to read any further. However, if the comment checkbox is not showing on your site, you need to keep reading and we'll show you how to add a privacy checkbox on WordPress.

Add a privacy check box for comments on WordPress

First of all, you need to make sure that you are using the latest version of WordPress and your theme. Just go to the page Dashboard »Updates to check for updates.

update wordpress.png

If an update is available for your current theme or WordPress, then go ahead and install it. Next, check your website's comment form to see if the update added the comment privacy checkbox.

If your theme and WordPress are both up-to-date, and you still don't see the comment privacy checkbox, it means your WordPress theme replaces the default WordPress comment form.

You can ask your theme author to resolve this issue by opening a support ticket. You can also try to fix it yourself until your theme author releases an update.

You can add comment privacy checkbox to your WordPress theme in two ways. We'll show you both methods, and you can try what works for you.

Both methods require you to add code to your files. WordPress theme. If you haven't already, check out our guide on to copy and paste code in WordPress.

1 method. Add a privacy check box in the comment form for your theme

This method is recommended because it attempts to protect the style and layout of the comment form for your theme.

First, you will need to find the code used to override the default WordPress comment form. Normally you can find it in comments.php or functions.php file in your theme folder.

You are going to look for a code using the 'comment_form_default_fields' filter. This filter is used by themes to replace the default WordPress comment form.

It will have lines for all of your comment form fields in a specific format. Here's a sample code to give you an idea of ​​what you're looking for:

$ comments_args = array (// change the title of the button 'label_submit' => esc_html (__ ('Post a comment', 'themename')), // change the title of the section 'title_reply' => esc_html (__ ( 'Leave a comment', 'themename')), // define a text box 'comment_field' => ' ',' fields '=> apply_filters (' comment_form_default_fields ', array (' author '=>' '.' '. ' ',' email '=>' '. ' '. ' ',' url '=>' '. ' '. ' ',)),); comment_form ($ comments_args); ?>

In this code, you can notice that the comment_form_default_fields is used to modify the author, email and URL fields. Inside the table, it uses the following format to display each field:

'fieldname' => 'The HTML code to display the field', 'anotherfield' => 'The HTML code to display the field',

We will add the optional comment privacy field towards the end. Here's what our code will look like now:

$ comments_args = array (// edit title for submit button 'label_submit' => esc_html (__ ('Post comment', 'themename')), // edit title for response section 'title_reply' => esc_html (__ ('Leave a comment', 'themename')), // redefine a text box 'comment_field' => ' ',' fields '=> apply_filters (' comment_form_default_fields ', array (' author '=>' '.' '. ' ',' email '=>' '. ' '. ' ',' url '=>' '. ' '. ' ', // Now we will add our new privacy checkbox optin' cookies '=>' '. ' '. __ ('Save my name, email, and website in this browser for the next time I want to comment.'). ' ',)),); comment_form ($ comments_args); ?>

2 method. Replacing the comment form of your theme with default WordPress

This method simply replaces your theme's comment form with the default WordPress comment form. Using this method may affect the appearance of your comment form and you may need to use leaves de style Custom CSS for stylize your comment form .

Edit the comments.php file for your theme and search for the line with the function comment_form(). Your theme will have a defined argument, function, or template inside to load your theme's custom comment form. Your comment_form line will look like this:


You will need to replace it with the following line:


Don't forget to save your changes and visit your website. You will now see the default WordPress comment form with the optional comment privacy checkbox.

optional check box for comments.png

We hope this article has helped you learn how to add the optional GDPR comment privacy checkbox on WordPress. You can also see our tips for get more feedback on your WordPress blog posts.