Adding a GDPR Comment Privacy Opt-in Checkbox in WordPress

The General Data Protection Regulation (GDPR) overhauls how businesses process and handle data. It came into effect on May 25, 2018, targeting how businesses and the public sectors handle the information of 750 million European citizens. The law exists in the EU but its reach is global. It is very crucial that you make your WordPress website GDPR compliant even if you’re not based on the EU. If you have comments enabled on your website, you need to add a comment privacy opt-in checkbox to comply with the new law and let your commenters know that you’ll be using their information. Adding a GDPR comment privacy opt-in checkbox in WordPress is quite easy. However, sometimes, you might come across a few issues while displaying the comment privacy opt-in checkbox. Therefore, in this article, we will be helping you to enable the checkbox and giving you its alternatives in case of any errors.

One of the many ways WordPress collects and stores the users’ data is through the comments. WordPress addressed the GDPR compliance in its 4.9.6 release. With the update, the default WordPress comment form provides the logged-out commenters the comment privacy opt-in checkbox—a choice on whether their name, email address and the website would be saved in a cookie on their browser for their next visit.

If you’ve updated to WordPress 4.9.6 or higher and your website is showing the comment privacy opt-in checkbox, then you do not need to perform any of the tasks below.

However, if your website is up-to-date and still not showing the checkbox, here is what you need to do.

First of all, you need to make sure your website is updated to the version 4.9.6 or higher and also, make sure you’re using the latest version of your current theme. Then, head over to Settings > Discussions tab and search for the ‘Show comments cookies opt-in checkbox’ in the Other comment settings section. You need to checkmark the option to enable the comment privacy opt-in checkbox.

checkmark the show comments cookies opt-in checkbox

Check-marking the option should do the job and your website should now display the comment privacy checkbox.

If the checkbox is still not showing up on your website, it means your WordPress theme is overriding the default WordPress comment form. You can ask your theme author to fix this issue by opening a support ticket. You can also try to fix it yourself until your theme author releases an update. Below are two methods you can use in order to add the comment privacy checkbox to your WordPress theme.

  • Add comment privacy checkbox to your theme’s comment form
  • Replace your theme’s comment form with the default WordPress comment form

Both of these methods require you to add code to your WordPress theme files. So, if you’re not familiar with coding or don’t want to mess around with code, you might want to wait for your theme author to help you out. Having said that, let’s move on with our article.

The first method is by adding comment privacy checkbox to your theme’s comment form. The method protects your theme’s comment form style and layout. First, find the code (using the ‘comment_form_default_fields’ filter) that has been used to override the default WordPress comment form. You can find it in the comments.php or functions.php file in your theme folder. It will have lines for all of your comment form fields in a specific format. It will look something like this:

 
$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);   ?> 

The comment_form_default_fields filter is used to modify the author, email, and URL fields. Inside the array, it uses the following format to display each field.

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

Now, add the comment privacy optin checkbox field towards the end. The code will now look something like this:

 
$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);   ?> 

Bringing these changes to your code will display the comment privacy opt-in checkbox in WordPress.

Now, the second method is by replacing your theme’s comment form with WordPress default comment form. The method can affect your comment form’s appearance, and you may have to use custom CSS to style your comment form.

Simply, edit your theme’s comments.php file and look for the line with the comment_form() function. Your comment_form line will look like:

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

Replace the above code with:

<?php comment_form(); ?>

Save the changes and visit your website to see your GDPR comment privacy opt-in checkbox in action with the default WordPress comment form.

Finally, we’ve come to an end of this article. We hope our guide helped you in adding a GDPR comment privacy opt-in checkbox in WordPress easily. You can use any of the above-mentioned methods that you think will be easy for you to perform.

If you have anything to ask or share, please feel free to drop your thoughts in the comments section.

Reference: WP Beginner

Leave a Reply

Your email address will not be published. Required fields are marked *