How to Change the URL For the reCAPTCHA Script

Overview

Are you interested in adjusting the location from which the Google reCAPTCHA script is loaded? If the default URL, with its associated cookies, doesn’t quite fit your needs, you’re in luck. With a simple PHP snippet, you can effortlessly modify the reCAPTCHA URL to better suit your preferences. Let’s walk through the steps to make this customization.

Setup

Simply add this snippet to your site. If you need any help in how to add snippets to your site, please see this tutorial.

/**
 * Change reCAPTCHA URL script
 *
 * @link   https://wpforms.com/developers/how-to-change-the-url-for-the-recaptcha-script/
 */

function wpf_dev_change_recaptcha_url( $captcha_api ) {
	
	return str_replace( 'https://www.google.com/recaptcha/api.js', 'https://www.recaptcha.net/recaptcha/api.js', $captcha_api );
	
}

add_filter( 'wpforms_frontend_captcha_api', 'wpf_dev_change_recaptcha_url', 10, 1 );

This snippet will look for the default reCAPTCHA URL and change it for what Google recommends.

And that’s it! Would you like to also change the language for reCAPTCHA? Check out our article on How to Set the Language for Google reCAPTCHA.