• Hi,
    I was wondering whether there is a way to defer the recaptcha script tag that is generated via integration with CF7.
    I noticed that it has the “async” attribute in the <script> tag that calls the recaptcha script, but it doesn’t seem to load asynchronously, so I want to try to defer it instead.

    How do I add the defer attribute to the <script> tag?

    Thanks
    Udi

Viewing 1 replies (of 1 total)
  • Hello,

    I’m not sure if you found a solution but I did some digging and found one that worked! I added this code in the ‘recaptcha.php’ file in the Contact-Form-7/Modules folder.

    function add_async_attribute($tag, $handle) {
        if ( 'google-recaptcha' !== $handle )
            return $tag;
        return str_replace( ' src', ' defer="defer" src', $tag );
    }
    
    add_filter('script_loader_tag', 'add_async_attribute', 10, 2);
Viewing 1 replies (of 1 total)

The topic ‘Adding “defer” attribute to recaptcha tag’ is closed to new replies.