Remove Google reCaptcha badge
I have a few websites that make use of Google reCaptcha to fend off spammers. For a while I’ve been using reCaptcha v3, which is the “invisible” one. The only problem is that it’s not really invisible, there’s always that annoying badge on the bottom right of every page. Even if you use a plugin that limits it to the login, registration, checkout page, whatever; it’s still there!
The solution can be found everywhere and basically entails simply adding a CSS selector for the .grecaptcha-badge class and setting the visibility to hidden. Now this does work for some cases and is a quick fix, but all the scripts are still loaded in the background, and then you have to provide a disclaimer in the workflow and it starts to get messy.
The better solution, I think, is to use a wordpress action hook and only load it on the pages that need it. That way you still have the badge, but it’s showing in all its glory only where it needs to be! Drop the below code into your functions.php file and modify it for the pages where you need it to display.
function semper_load_recaptcha_badge() { if ( !is_page( array( 'checkout', 'login' ) ) ) { wp_dequeue_script('google-recaptcha'); } } add_action( 'wp_enqueue_scripts', 'semper_load_recaptcha_badge', 100 );
This will work if your reCaptcha plugin has named its script as ‘google-recaptcha’. I use the Kadence reCaptcha plugin for my needs and they call their script ‘ktv3-google-recaptcha’ so I used that instead. My particular setup for one of my sites looks like this:
function semper_load_recaptcha_badge() { if ( !is_page( array( 'checkout', 'login', 'contact' ) ) ) { wp_dequeue_script('ktv3-google-recaptcha'); } } add_action( 'wp_enqueue_scripts', 'semper_load_recaptcha_badge', 100 );
You can see I need it on my login, checkout and contact pages.