To fix the “Missing form label” WAVE error on reCAPTCHA v3 when using Gravity Forms, add the following code to your functions.php file:
/**
* Fix WAVE error: "Missing form label" on Google reCAPTCHA v3.
*/
add_action( 'wp_enqueue_scripts', function() {
if ( class_exists( 'Gravity_Forms\Gravity_Forms_RECAPTCHA\GF_RECAPTCHA' ) ) {
wp_add_inline_script(
'gforms_recaptcha_recaptcha',
'(function($){grecaptcha.ready(function(){$(\'.grecaptcha-badge\').css(\'visibility\',\'hidden\');$response=$(\'.g-recaptcha-response\');$response.attr(\'aria-hidden\',\'true\');$response.attr(\'aria-label\',\'Ignore this field.\');});})(jQuery);'
);
}
}, 99 );
If you are still using reCAPTCHA v2 (with Gravity Forms), add this code to your javascript file instead:
/**
* Fix WAVE error: "Missing form label" on Google reCAPTCHA v2.
*/
if ( 'undefined' != typeof( gform ) ) {
gform.addAction('gform_post_recaptcha_render', function (elem) {
$response = jQuery( elem ).find( '.g-recaptcha-response' );
$response.attr( 'aria-hidden', 'true' );
$response.attr( 'aria-label', 'Ignore this field.' );
});
}