My Page Speed Insights are failing due to "unused javascript". The file in question is being loaded by gstatic.com. After searching the file structure of my wordpress site, it seems that it's coming from the Types plugin. I can't figure out how to disable this to improve my page speed. I'd be willing to use a different recaptcha plugin that's not built into Types that will give me more control over which pages it's loaded on as right now it's loaded globally, even on non "contact us" pages.
Hello and thank you for contacting the Toolset support.
Currently, there is no built-in way in WordPress or Toolset to achieve this. You will need to use custom code to change how the script is being added. For example, the following code will add the "defer" attribute to the script tag:
add_filter( 'clean_url', function( $url )
{
if ( FALSE === strpos( $url, 'www.google.com/recaptcha/api.js' ) )
{ // not our file
return $url;
}
// Must be a ', not "!
return "$url' defer='defer";
}, 11, 1 );
You can explore different techniques in this StackOverflow thread https://stackoverflow.com/questions/18944027/how-do-i-defer-or-async-this-wordpress-javascript-snippet-to-load-lastly-for-fas
You may also want to use a 3rd Party plugin such as "Async JavaScript" https://wordpress.org/plugins/async-javascript/
Note that our script handler is called "wpt-cred-recaptcha". Check this screenshot hidden link
I hope this helps. Let me know if you have any questions.