Add the following code to the function:
/*=Add ReCaptcha to registration form
/****************************************************/
function oley_add_recaptcha_field() {
?>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<p>
<label for="recaptcha"><br />
<div class="g-recaptcha" data-sitekey="6LeMTZ8UAAAAADPQsTUpY6Vu-AIuaHYpaXtW4BjE"></div>
</label>
</p>
<?php
}
add_action( 'register_form', 'oley_add_recaptcha_field' );
function oley_validate_recaptcha_field( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['g-recaptcha-response'] ) ) {
$errors->add( 'recaptcha_error', __( '<strong>ERROR</strong>: Please verify that you are not a robot.', 'oleymediagroup' ) );
}
return $errors;
}
add_filter( 'registration_errors', 'oley_validate_recaptcha_field', 10, 3 );
Note that you must enter your site key