Speed up Contact Form 7

By Hella Fast

★ 4.7/5 (3 ratings)300+ active installationsVersion 1.2.0

Loads Contact Form 7, reCAPTCHA, Turnstile and add-on assets only on pages that actually show a form.

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.

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.