Add Google reCAPTCHA v3 to CF7
Integrates Google reCAPTCHA v3 with Contact Form 7
PHP
function add_recaptcha_v3() {
?>
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_SITE_KEY"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('YOUR_SITE_KEY', {action: 'contact'}).then(function(token) {
var forms = document.getElementsByTagName('form');
for (var i = 0; i < forms.length; i++) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'g-recaptcha-response';
input.value = token;
forms[i].appendChild(input);
}
});
});
</script>
<?php
}
add_action('wp_footer', 'add_recaptcha_v3');
Snippet Feedback
Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY