Makes Contact Form 7 and several add-ons to load only on pages with a form.…
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.
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
Error: Contact form not found.
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