Speed up Contact Form 7
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
- Install and activate Contact Form 7.
- 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
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();
} );
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;
} );
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
Worked great! Does exactly what it says.
By joeaudet on April 12, 2021
Very speed and safe
By teim on February 20, 2021
Does exactly what it says it does
By Thyrosis on January 28, 2021
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_cssswitches 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.