Background

During our process of adapting to the new GDPR (General Data Protection Regulation) at APG we have found ourselves obliged to add the acceptance of our privacy policy in the comment publishing form, and what at first sight looked as if it was going to be something very simple, we can already tell you was not quite so simple.

In our particular case we were using the Jetpack by WordPress.com comments form, which we have always liked a lot because of how easy it makes it for users to be able to comment from their accounts on Twitter, Facebook or Google+, but which, given that it is loaded through an iframe directly from WordPress.com, and however much we have tried to manipulate the filters and actions it offers, we have not managed to make work the way we wanted and needed.

On the other hand we tried a plugin from the official WordPress.org repository that promised to solve this need with a single click, but it was no use to us either, since this plugin in fact not only is not functional enough but also makes it impossible to publish replies to the comments from the administration panel.

Lastly we also had to keep the blog and comment subscription options that Jetpack by WordPress.com offers us and which, when you remove the comments form it offers natively, turn out to be added after the Submit button, so we were not quite finding a feasible solution and in the end we had to roll up our sleeves a little and get down to work creating a bit of custom code.

By the way, with the subscription field for our mailing list we did not have any kind of problem, so that is why we do not make any kind of reference to this specific field.

How have we done it?

To manage to add the privacy policy in the comments we have created two PHP functions in the functions.php file of our child theme, specifically these two:

Copy to clipboard

The first of the functions, apg_sobrescribiendo_jetpack, removes the subscription fields so as to prevent them from appearing after the Submit button of the form, and the second function, apg_campos_comentarios, is the one that takes care of adding the two native Jetpack by WordPress.com fields and the new privacy policy acceptance field just before the Submit button.

The good thing about the formula we have chosen is that, by using 100% native WordPress code, it does not require any kind of additional JavaScript or PHP code to check that the privacy policy acceptance field has been ticked before allowing the form to be submitted; the native code already used and loaded by the comments form itself will take care of that action.

If you want to see this code in action you only have to scroll down to the comments form of this very post.

All right, but what if I do not use Jetpack by WordPress.com?

If you do not use the subscription options that Jetpack by WordPress.com offers you, things are considerably simpler, since in that case you only have to add a single PHP function in the functions.php file of your child theme, specifically this one:

Copy to clipboard

We hope that either of the two solutions we are proposing solves the problem that the new legislation poses for you with the comments form and that we are quite sure is going to come up for you in practically all your projects.

As always, we remain on the lookout for your comments and contributions.

UPDATE:

In the event that your theme does not validate the comments directly, for these pieces of code to be functional you will need to add this other PHP code in your functions.php file to make everything work as it should:

Copy to clipboard

Related posts

Comments

Suscríbete
Notificar de
0 Comments
Más antiguos
Más recientes Más votados

In this post

Products and services

Latest posts

Latest comments

Subscribe!

Lista de correos de APG

DATA PROTECTION: In accordance with data protection regulations, we provide you with the following processing information: (+)

  • Responsible: Art Project Group.
  • Treatment purposes: to respond to queries or any type of request made by the user through any of the forms of contact that are made available on the website. Sending communications about products or services (with your consent).
  • Your rights: access, rectification, portability, deletion, limitation and opposition. More information about the treatment in the Privacy Policy.

What we post on !

Se ha publicado #WooCommerce 11.2.2: actualización de seguridad que refuerza las API REST y Store, mejora la validación de CSV y corrige problemas en pagos y pedidos. Incluye cambios en la base de datos.

¡Actualiza cuanto antes!

November 5, 2026