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.

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.