CF7 reCaptcha V3 not working due to JS deferring – FIX
-
After spending some time investigating the issue I have had with CF7’s reCaptcha V3 integration I’ve found that it was due to the fact that Javascript was being deferred globally.
So, for anyone else who wants to continue deferring JS here’s what I used:
function defer_parsing_of_js( $url ) { if ( is_user_logged_in() ) return $url; //don't break WP Admin if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.js' ) ) return $url; // Dont defer recaptcha if ( strpos( $url, 'recaptcha/api.js' ) ) return $url; return str_replace( ' src', ' defer src', $url ); } add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );
You can then add additional exceptions for any JS that can’t be deferred for one reason or another. This can also be adapted to load JS asynchronously by switching out ‘defer’ for ‘async’.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘CF7 reCaptcha V3 not working due to JS deferring – FIX’ is closed to new replies.