Hello @the-dude-1,
In fact, if I remember correctly, CF7 has always loaded CSS and JS on all pages to make sure the forms work properly (not only since the last version). This is a topic discussed many times in the plugin support forum and there are several technical reasons why it’s not added to the core of the plugin. However, there are also several ways to solve it.
My recommendation is to follow the steps you’ll find in this article from the official documentation: Loading JavaScript and stylesheet only when it is necessary.
If you prefer to use a code snippet, you can try adding this one in the functions.php
file of your child theme or using a custom plugin (recommended):
add_action( 'wp_enqueue_scripts', 'wpcf7_scripts_removal_contact_form_7', 999);
function wpcf7_scripts_removal_contact_form_7() {
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' );
}
}
This code snippets will remove the CSS and JS of CF7 from all post and pages that don’t include a CF7 form shortcode in its content. Please note this also remove the CSS and JS from the archives pages and widgets, so it’s not a good idea to use it if you have set a form within a widget.
Hope this helps you.
Best regards,
Yordan.