• Resolved Joshaw

    (@joshaw)


    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)
  • Thread Starter Joshaw

    (@joshaw)

    Update: I’ve found that the reCaptcha script can actually be deferred and the form work successfully (according to another user – I haven’t personally confirmed this) so if you want to defer the script and it’s not working, try reordering your scripts. I’m just going to leave mine not being deferred for now ??

    • This reply was modified 4 years, 7 months ago by Joshaw.
    • This reply was modified 4 years, 7 months ago by Joshaw.
Viewing 1 replies (of 1 total)
  • The topic ‘CF7 reCaptcha V3 not working due to JS deferring – FIX’ is closed to new replies.