6

I have a site that scores well on Google Page Speed Insights, but it shows a performance issue that says "Remove unused JavaScript" for this file:

https://www.gstatic.com/recaptcha/releases/2diXFiiA9NsPIBTU15LG6xPf/recaptcha__en.js

However, I have tried removing my Invisible Captcha plugin, and also adding this line of code to functions.php:

add_action('wp_print_scripts', function () {
    if ( is_home() ){
        wp_dequeue_script( 'google-recaptcha' );
        wp_dequeue_script( 'google-invisible-recaptcha' );
    }
});

But I still get the error. Is there anything I can do to remove this script from loading on my home page? My site is using the latest version of Wordpress.

Alex Douglas
  • 534
  • 1
  • 8
  • 21

1 Answers1

0

the below worked for me:

add_action( 'wp_enqueue_scripts', 'mytheme_deregister_scripts' );
function mytheme_deregister_scripts() {
  if( is_home() || is_front_page() ) :
    wp_deregister_script('google-invisible-recaptcha');
  endif;
}
Vaiman Hunor
  • 404
  • 1
  • 4
  • 12