Google reCAPTCHA is a popular tool used to prevent spam and bots from submitting contact forms on WordPress websites. However, it can be quite distracting to have the reCAPTCHA badge displayed on the homepage of your website. In this article, we’ll show you how to remove the Google reCAPTCHA badge from the homepage in WordPress Contact Form 7, so that your website visitors can focus on your content without any distractions.
To only display the reCAPTCHA on the contact page, you’ll need to add some custom functionality to your website. Add the following code to your theme’s functions.php file:
function wpd_remove_recaptcha_badge() {
if ( !is_page( array( 'contact' ) ) ) {
wp_dequeue_script( 'google-recaptcha' );
wp_deregister_script( 'google-recaptcha' );
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
}
}
add_action( 'wp_print_scripts', 'wpd_remove_recaptcha_badge' );
This code will only enqueue the Google reCAPTCHA script if the page being viewed has the slug “contact”. If you want to use a different page slug, change “contact” in the is_page()
function to the slug of the page you want to use. You can add even more than one slug.