Load Contact Form 7 CSS and JS files only when necessary
10 June 2019
I was looking the other day for a way to optimize a website that uses CF7 for SEO and I realized that basically the plugin is not so well developed from a loading speed point of view (and therefore SEO problems) because the CSS and JS files are always loaded, by default on every page.
Here you can find a PHP snippet to paste into your functions.php, in order to dequeue those styles and scripts and load them only on the pages that actually use a contact form.
You’ll have only to adjust the 2 arrays $pages_cf7_add_scripts and $single_cf7_add_scripts inserting the slugs where the scripts will be loaded.