How to Change the URL For the reCAPTCHA Script

Overview

Would you like to change the URL that the Google reCAPTCHA script is loaded from? If you rely on cookies that the default URL uses, you may find it useful to change the reCAPTCHA URL. Using a small PHP snippet you can easily change this URL and we’ll show you how.

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.