0

I am using polylang to translate my wordpress site, it is in Japanese and english. The forms are built with contact form 7.

I found a some code to change the reCAPTCHA language from english to Japanese using the code below:

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' => 'ja'), $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 );

This makes all my forms display the reCAPTCHA in Japanese, is there a way I can make the reCAPTCHA on the english pages display in English and Japanese on the Japanese pages?

rjdesign
  • 1
  • 2

1 Answers1

2

That's because you're just setting it to japanese all the time. To get current language locale from Polyland, use pll_current_language()

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' => pll_current_language('slug')), $url);
    wp_register_script('google-recaptcha', $url, array(), '2.0', true);
}

add_action('wpcf7_enqueue_scripts', 'wptricks24_recaptcha_scripts', 11);
Igor Yavych
  • 4,166
  • 3
  • 21
  • 42