Created
July 22, 2021 11:24
-
-
Save codenathan/f95828d30ef54c9458a73a1b78876b10 to your computer and use it in GitHub Desktop.
WordPress - Hide Google Recaptcha Except Contact Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* CONTACT FORM 7 */ | |
// This code enables to disable contact form 7 from loading on every page except the contact page | |
// This form also disables the Google recaptcha from loading on every page | |
// add the following in your functions.php | |
// to hide the captcha badge using CSS method check out the following link : | |
// https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed | |
// Stop the CF7 CSS & JS FROM LOADING ON EVERY PAGE | |
add_filter( 'wpcf7_load_js', '__return_false' ); | |
add_filter( 'wpcf7_load_css', '__return_false' ); | |
function disable_google_recaptcha_except_contact() | |
{ | |
//Remove the captcha scripts if its not on the contact form | |
if (!is_page(array( 'contact')) ) : | |
wp_dequeue_script('wpcf7-recaptcha'); | |
wp_dequeue_script('google-recaptcha'); | |
else : | |
// else if it is the contact form enqueue all the scripts related to CF7 | |
if (function_exists('wpcf7_enqueue_scripts')) { | |
wpcf7_enqueue_scripts(); | |
} | |
if (function_exists('wpcf7_enqueue_styles')) { | |
wpcf7_enqueue_styles(); | |
} | |
endif; | |
} | |
add_action('wp_enqueue_scripts', 'disable_google_recaptcha_except_contact'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment