Contact form 7 : how to change language of recaptcha in WordPress
We are using contact form 7 for forms in wordpress very frequently. As we know if we are preparing a form then we will definitely add a captcha to that form. So, for adding captcha in contact form 7 we choose recaptcha which is a google service.
Now, in case when we are preparing a website other than the English language using both of the plugins than we face a issue of recaptcha translation. Normally recaptcha is in English language by default.
In this case, we have added a contact form 7 plugin and recaptcha plugin. Now we want to change the language of recaptcha with out modifying the plugin core files. To do this just take a example language that is Spanish for now. Now we want to show our recaptcha will show in Spanish language.
Just open the functions.php file of your current theme and paste the below mentioned code :
function wptricks24_recaptcha_scripts() { wp_deregister_script( 'google-recaptcha' ); $url = 'https://www.google.com/recaptcha/api.js'; $url = add_query_arg( array( 'onload' => 'recaptchaCallback', 'render' => 'explicit', 'hl' => 'es'), $url ); // es is the language code for Spanish language wp_register_script( 'google-recaptcha', $url, array(), '2.0', true ); } add_action( 'wpcf7_enqueue_scripts', 'wptricks24_recaptcha_scripts', 11 );
After putting the above code as explained above, our recaptcha will be in Spanish language. All the recaptcha options will automatically converted into Spanish language.
Now we can modify it to any of the language, just look at the above code we are using ‘hl’ => ‘es’ where “es” is the language code for Spanish language. We can create this recaptcha with few more languages at a time by applying the conditions to the code. We just need to pass the language code of our choice to “hl” parameter.
If you are facing reloading issue with recaptcha check here : recaptcha reset not working.
Hi, I was about to use this code, but why do you have wptricks24 (your website name) in the script, what does it do?
Nothing..it is just a name of callback function..which is attached to the hook we are using..I have used my website name, in the same manner you can use your own function name like “drazen_recaptcha_scripts” if you want…but if you remain it as it is it will also work perfectly..
In contact form 7, I entered a field to upload files. The text in the place holder field continues to appear in Dutch. I would like it to appear in English. How can I solve this?
Hi, I’m wondering how you have either english or spanish as a choice for the CAPTCHA? We have a language toggle so that guests can choose between english or spanish, and I would like the spanish Captcha to appear on the spanish-language form, and english on english.
Just check here: http://www.wptricks24.com/contact-form-7-change-recaptcha-language-using-qtranslate-x-plugin
Look at the “h1” parameter, it is having “qtranxf_getLanguage()” which is current language code, it is for qtranslate plugin.
In the same manner, just pass your dynamic language code in “h1” parameter, you will get your desired result.
Hopefully it will help you 🙂
Just add simple line to your code to check active page lang
function wptricks24_recaptcha_scripts() {
wp_deregister_script( ‘google-recaptcha’ );
$pagelang= get_bloginfo(“language”); //this line to check the active lang
$url = ‘https://www.google.com/recaptcha/api.js’;
$url = add_query_arg( array(
‘onload’ => ‘recaptchaCallback’,
‘render’ => ‘explicit’,
‘hl’ => $pagelang), $url ); // language by check the active on the page
wp_register_script( ‘google-recaptcha’, $url, array(), ‘2.0’, true );
}
add_action( ‘wpcf7_enqueue_scripts’, ‘wptricks24_recaptcha_scripts’, 11 );
Hi,
This works great, however it seems like every now and then the recaptcha on my page gets back to English (I suspect this is when the theme is updated). Is there any solution to this, other than changing the functions.php file after each update?
Thanks!