Skip to content

Instantly share code, notes, and snippets.

@cleot
Last active April 10, 2021 19:34
Show Gist options
  • Save cleot/a870cf5d4b5035163eb2cb3d07a87cb8 to your computer and use it in GitHub Desktop.
Save cleot/a870cf5d4b5035163eb2cb3d07a87cb8 to your computer and use it in GitHub Desktop.
Disable reCaptcha Badge & Plugin for all pages except for pages with contact forms (Wordpress, Contact Form 7, Google reCAPTCHA v3)
add_action( 'wp_enqueue_scripts', 'gbol_remove_wpcf7_resources_if_no_contact_form', 1 );
function gbol_remove_wpcf7_resources_if_no_contact_form() {
global $post, $gbol_css_dependencies, $abcf7;
if ( isset( $post ) && is_singular() && has_shortcode( $post->post_content, 'contact-form-7' ) ) {
return;
}
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 20 );
}
/** source: https://wordpress.org/support/topic/recaptcha-badge-on-all-pages-not-just-pages-with-contact-forms/page/9/#post-14125519 **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment