What: Stop cf7 enqueing CSS and JS on pages with no contact forms (seems like something the plugin author should have done, right?.. )
Why: Cos of site speed. Google site health is a thing now. every millisecond for page load and render is critical. less scripts / kludge = faster site, happy google, happy users.
How: put this code in your theme or child theme functions.php
Code:
function rjs_lwp_contactform_css_js() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact-form-7') ) {
wp_enqueue_script('contact-form-7');
wp_enqueue_style('contact-form-7');
}else{
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'rjs_lwp_contactform_css_js');
hopefully saves some of ye some milliseconds