Speed up Contact Form 7

Description

Stop loading Contact Form 7 on pages that don’t have a form.

Contact Form 7, reCAPTCHA, Cloudflare Turnstile and most CF7 add-ons load their scripts and styles on every page of your site. On a typical site, that’s 8 extra files on pages with no form. This plugin keeps them only where a form actually appears.

  • No settings. Activate it and you’re done.
  • Works with the shortcode, the CF7 block, widgets, page builders and block themes.
  • If a form shows up somewhere unexpected, its files load automatically, so forms never break.
  • Holds back reCAPTCHA v3, Turnstile, Stripe and any add-on that depends on Contact Form 7.

Built by Roman’s design.

Installation

  1. Install and activate Contact Form 7.
  2. Install and activate this plugin.

That’s it. It has been tested on dozens of client websites, but check your contact forms after activating it, just in case 🙂

FAQ

My form is inside a popup or loaded with AJAX and stopped working

The plugin can’t see forms that are injected after the page loads. Force the assets on for those pages:

add_filter( 'sucf7_load_assets', function ( $load ) {
    return $load || is_front_page();
} );

How do I hold back another add-on’s script or style?

Add-on assets that depend on Contact Form 7 are handled automatically. For others, add their handles:

add_filter( 'sucf7_extra_handles', function ( $handles ) {
    $handles['scripts'][] = 'my-addon-script';
    $handles['styles'][]  = 'my-addon-style';
    return $handles;
} );

Does reCAPTCHA v3 still protect my forms?

Yes. reCAPTCHA still loads on every page with a form. Google recommends loading v3 site-wide so it can see more of a visitor’s behavior, so scores may be slightly less accurate. If you’d rather keep it everywhere, remove google-recaptcha and wpcf7-recaptcha from the list with the sucf7_extra_handles filter.

Reviews

12. April 2021
This worked great to solve my issue of the ReCaptcha v3 showing up on EVERY page with Contact Form 7. I tried several variations of code for disabling the loading of the scripts on pages that were not my contact form, and none of them worked properly. This was tested with WP v5.7 and CF7 v5.4 successfully, confirmed with a debug / fiddler trace that the scripts were not downloaded by the client.
28. Januar 2021 1 reply
This plug-in does exactly what it says it does. But, even more important: it removes the Google reCaptcha files from all the pages that don't use a Contact Form 7 form in the page. This is not only a speed-boost, but makes your website less Googly and more privacy friendly. It doesn't take a sidebar into account though (hence the 4*). But, for the site I'm currently working on, that's not an issue. I'm very happy with the simplicity of this plug-in and would definitely recommend it.
Read all 3 reviews

Contributors & Developers

“Speed up Contact Form 7” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

1.2.0

  • Tested with WordPress 7.1 and Contact Form 7 6.x.
  • Uses Contact Form 7’s built-in wpcf7_load_js / wpcf7_load_css switches instead of dequeuing after the fact.
  • Detects the Contact Form 7 block and the [contact-form] shortcode alias.
  • Holds back Cloudflare Turnstile, Stripe, the SWV validation script and any add-on asset that depends on Contact Form 7.
  • New: forms in widgets, page builders and templates keep working (assets load automatically when a form is rendered).
  • New filters: sucf7_load_assets, sucf7_extra_handles.
  • Fixed the readme «Stable tag».

1.1

  • Support for the Redirection for Contact Form 7 add-on.

1.0

  • Initial release.