Performance and monitoring
How to load the reCAPTCHA script with Contact Form 7 only where it is needed
Contact Form 7 can load reCAPTCHA v3 on pages without a visible form. This gives context to the analysis of interactions. The developer advises against limiting it to a few pages because it can reduce the accuracy of bot detection.
Before changing it, measure its cost and check which anti-spam integration your installation actually uses. Hiding the badge or delaying the script is not the same as removing its download, nor does it keep the protection intact.
Why searching for a shortcode is not enough
A form can be in a template, reusable block, page builder, widget, modal or footer. Searching only for the shortcode in the post content can remove the scripts where they are still needed.
If you decide to make an adaptation, first list every form and any other component that uses the Google script. Test it on a copy with the same cache configuration.
Example limited to identified pages
This example keeps the scripts on two pages whose IDs you must replace and avoids acting on views that are not pages. It is only valid if you have checked that there are no forms or other reCAPTCHA integrations on the excluded pages.
Add it to a site-specific plugin or to a child theme under version control. Do not edit the parent theme, because an update can overwrite it.
add_action('wp_enqueue_scripts', function () { if (is_admin() || !is_page()) { return; } // Sustituye estos IDs por TODAS las páginas que necesitan reCAPTCHA. $paginas_con_recaptcha = [123, 456]; if (!is_page($paginas_con_recaptcha)) { wp_dequeue_script('wpcf7-recaptcha'); wp_dequeue_script('google-recaptcha'); } }, 100);
This is a customisation, not a guaranteed official option. Script handles and the way they load can change between versions. Other plugins could enqueue them again; confirm the result in the browser.
Validate and maintain
Test every form as a visitor: loading, validation, submission and receipt at a controlled test address. Check the console, network and anti-spam diagnostics; also test forms that appear after an interaction.
Purge the cache of the affected pages and watch whether spam or legitimate rejections increase. Remove the code if the protection degrades or a form breaks.
Every new page with a form and every update to the integration means reviewing this list. If you cannot keep it complete, keep the loading recommended by Contact Form 7 and prioritise other performance improvements.
You may also find useful
- Diagnose slow LEFT JOIN queries in WordPress Analyse slow taxonomy queries with LEFT JOIN, compare plans and alternatives on a copy and avoid unm...
- Improve WordPress database performance with Index WP MySQL For Speed Assess WordPress indexes with Index WP MySQL For Speed, review the changes before applying them and...
- Optimise the wp_options table and "autoload" data Measure and reduce autoloaded data in wp_options, find large options, cron, transients and sessions,...
- Replace WP-Cron with a hosting cron job Set up a system task to run WordPress events, check that it works and avoid leaving tasks pending wh...
Something wrong or out of date? Tell us and we will review it.