How to Change the Captcha Theme on Google Checkbox v2 reCAPTCHA

Introduction

Would you like to change the captcha theme on your forms when using Google Checkbox v2 reCAPTCHA? With a little JavaScript you can change this theme to a Dark theme. In this tutorial, we’ll walk you through the steps needed to change the captcha theme.

By default, when using reCAPTCHA, the theme of the captcha box is set to Light.

the default theme for the captcha is set to light

Creating the form

First, we’ll begin with creating our form and adding our fields. If you need any help in how to create a form, please review this documentation.

Enabling reCAPTCHA on your form

Next, you’ll need to set up reCAPTCHA to your form. If you need assistance setting this up you can review our full documentation on How to Set Up reCAPTCHA in WPForms.

The code shown below is specifically for the Google Checkbox v2 reCAPTCHA setting that you’ll enable on your form’s Settings » Spam Protection and Security tab.

Enable Google reCAPTCHA on your form under the General tab of your form settings

Adding the JavaScript to your site

In the code snippet below we’ll be adding a tag attribute to the .g-recaptcha div and set a data-theme tag to have a value of dark. This is what will change the captcha theme on the form.
Now that reCAPTCHA has been added to your form, you can see what it looks like by default.

You can take a look at the reCAPTCHA Developers Guide from Google if you’d like to change any of the other default attributes.

Finally, you’ll need to add the following code snippet to your site. If you need any help in how to add snippets to your site, please review this tutorial.

/**
 * Change the captcha theme for the Google Checkbox v2 reCAPTCHA
 *
 * @link https://wpforms.com/developers/how-to-change-the-captcha-theme-on-google-checkbox-v2-recaptcha/
 */

function wpf_dev_change_captcha_theme( ) {
?>

    <script type="text/javascript">

	jQuery(function($){

	    $( '.g-recaptcha' ).attr( 'data-theme', 'dark' );

        });

    </script>

<?php
}

add_action( 'wpforms_wp_footer_end', 'wpf_dev_change_captcha_theme', 30 );

Once the code has been added to your site, your captcha theme will now be set to Dark.

With the code above you can now change the captcha theme to dark

This snippet will also change the theme of the Invisible reCAPTCHA v2 as well as hCAPTCHA.

And that’s it! You’ve successfully changed the captcha theme from Light to Dark. Would you like to change the styling on the form’s placeholder text? Take a look at our article on How to Style Placeholder Text for Form Fields.

Action Reference: wpforms_wp_footer_end

FAQ

Q: Can I also change the theme for hCAPTCHA?

A: Absolutely, you don’t even need another script for this! You can use the same snippet to change the theme to dark for both reCAPTCHA v2, Invisible reCAPTCHA v2, and hCAPTCHA.