Site icon Anthony Carbon

Uncaught TypeError: grecaptcha.render is not a function

Uncaught TypeError: grecaptcha.render is not a function console error is showing if the recaptcha api.js is not enqueue or the `grecaptcha.render` is fire before the recaptcha api.js is being enqueue. See the JS library link below.

https://www.google.com/recaptcha/api.js?hl=en&render=explicit

I’m having this error when I use the Gravity Form captcha field.

As I explained above, that is the cause of error. To fix this error, the easiest way is install 4nton Extensions.

And the other options is to add this code to your functions.php of your current theme.

First is we have to remove the existing JS library to avoid duplicate injection of JS library.

add_action( 'wp_footer', 'ae_wp_footer_action' );
function ae_wp_footer_action(){
	$wp_scripts = wp_scripts();
	if ( is_array( $wp_scripts->queue ) ) {
		if ( in_array( 'gform_recaptcha', $wp_scripts->queue ) ) {
			$wp_scripts->dequeue( 'gform_recaptcha' );
		}
	}
}

Then re-inject it to wp head of your page.

add_action( 'wp_head', 'ae_wp_head_action' );
function ae_wp_head_action(){
	printf( '<script type="text/javascript" src="%s"></script>', 'https://www.google.com/recaptcha/api.js?hl=en&render=explicit' );
}

NOTE: make sure to update your Gravity Form to `gravityforms.2.3.1`. Not sure if this is working below 2.3.1.

That’s it! our job is done.

Exit mobile version