# Load Contact Form 7 reCAPTCHA Only on Form Pages

> Stops the Google reCAPTCHA script that Contact Form 7 adds to every page from loading where no form is shown, which speeds up the rest of the site and hides the badge there.

- Type: PHP
- Runs: Frontend only
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, recaptcha, performance
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-recaptcha-only-with-forms/

## Code

```php
$wpide_cf7_recaptcha_pages = array(); // Extra page IDs that show a form outside the content.

add_action( 'wp_enqueue_scripts', function () use ( $wpide_cf7_recaptcha_pages ) {
    $post = get_post();
    $uses = $post && is_singular() && ( has_shortcode( $post->post_content, 'contact-form-7' ) || has_block( 'contact-form-7/contact-form-selector', $post ) );

    if ( $uses || ( $wpide_cf7_recaptcha_pages && is_page( $wpide_cf7_recaptcha_pages ) ) ) {
        return;
    }

    wp_dequeue_script( 'wpcf7-recaptcha' );
    wp_dequeue_script( 'google-recaptcha' );
}, 50 );
```

## Notes

Add page IDs to the list if a form appears outside the post content, for example in a footer widget.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Load Contact Form 7 reCAPTCHA Only on Form Pages" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
