How to Set the Language for Google reCAPTCHA

Overview

Would you like to set the language for Google’s v2 reCAPTCHA? Google will try and auto-detect the language on the page when using reCAPTCHA. In some cases it’s detection doesn’t work and in other use cases, you may just want to force it to something different. With a small PHP snippet, you can easily set the language inside a filter.

Setup

In our code example below, we’re going to set the reCAPTCHA language to French.

First, you’ll need to set up Google v2 reCAPTCHA on your form. If you need any assistance with that, please view this tutorial.

Next, you’ll need to copy this code to your site.

/**
 * Set a specific language reCAPTCHA.
 *
 * @link https://wpforms.com/developers/how-to-set-the-language-for-google-recaptcha/
 * 
 */
function wpf_dev_recaptcha_language( $url ) {

	return esc_url_raw( add_query_arg( array( 'hl' => 'fr '), $url ) );
}
add_filter( 'wpforms_frontend_recaptcha_url', 'wpf_dev_recaptcha_language' );

Once the code is added, you can now see the I’m not a robot question has been translated to French.

now the language for google recaptcha is set to french

And that’s all you need to force the reCAPTCHA language. Would you like to also change the look of reCAPTCHA? Take a look at our article on How to Change the Captcha Theme on Google Checkbox v2 reCAPTCHA.

Filter Reference: wpforms_frontend_recaptcha_url