Load Contact Form 7 JS Scripts Only When Needed

Contact Form 7 loads its scripts on all pages which uses memory and increases load time.

Add this to functions.php to only load scripts when required:

// only load js scripts for wpcf7 on contact and join pages
// Add the Contact Form 7 scripts on selected pages

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
if ( !is_page(array(42,35)) ) {
wp_deregister_script( 'contact-form-7' );

Leave a Comment