Add a hidden field and a time check to the WordPress registration form, rejecting bots that fill it in or submit instantly.
add_action( 'register_form', function (): void {
echo '<p style="position:absolute;left:-9999px" aria-hidden="true"><label>Leave this empty <input type="text" name="nahnu_website" value="" tabindex="-1" autocomplete="off"></label></p>';
printf( '<input type="hidden" name="nahnu_form_time" value="%d">', time() );
} );
add_filter( 'registration_errors', function ( WP_Error $errors ): WP_Error {
$filled = ! empty( $_POST['nahnu_website'] );
$time = (int) ( $_POST['nahnu_form_time'] ?? 0 );
$fast = $time > 0 && ( time() - $time ) < 3;
if ( $filled || $fast ) {
$errors->add( 'nahnu_spam', '<strong>Error:</strong> Registration failed. Please try again.' );
}
return $errors;
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
If “Anyone can register” is on, bots will create accounts on your site. A honeypot is a field humans never see but bots fill in. This snippet adds one to the registration form, plus a check for forms submitted faster than a person could type.
The register_form action adds a text field moved off-screen and hidden from screen readers, and a hidden timestamp. The registration_errors filter rejects the registration if the hidden field has any value, or if the form came back less than three seconds after it was shown.
Real visitors never see the extra field, so there’s no CAPTCHA to solve.
woocommerce_register_post instead.Register normally in a private window. It should work. Then use DevTools to fill in the hidden field and submit: you should get the error.