Home / Admin / Defer the reCAPTCHA Script
Duplicate Snippet

Embed Snippet on Your Site

Defer the reCAPTCHA Script

Defers the reCAPTCHA script until after the page finishes loading.

100+
Code Preview
php
<?php
/**
 * Defer the reCAPTCHA script until after the page loads
 *
 * @link   https://wpforms.com/developers/how-to-defer-the-recaptcha-script/
 * 
 * For support, please visit: https://www.facebook.com/groups/wpformsvip
 */
function wpf_recaptcha_add_async_defer( $tag, $handle ) {
 
            if ( strpos( $tag, 'recaptcha/api.js?onload=wpformsRecaptchaLoad' ) !== false ) {
                $tag = str_replace( ' src', ' defer async="async" src', $tag );
            }
 
            return $tag;
 
        }
 
add_filter( 'script_loader_tag', 'wpf_recaptcha_add_async_defer', 10, 2 );

Comments

Add a Comment