Search Knowledge Base by Keyword

How to add CAPTCHA to a WordPress website form

You are here:

There are two ways how you can add CAPTCHA to a form on WordPress with the Advanced noCaptcha & invisible Captcha plugin. If your form is custom PHP script, then you can add the CAPTCHA via PHP code. If your form can be edited from the WordPress dashboard, you can simply add a short code. Below is an explanation of each of the methods.

Adding the CAPTCHA in the PHP code

If the form where you want to add the CAPTCHA cannot be edited from the WordPress editor, then you can simply add the below line of code to the form’s PHP file. You should add this line just before Submit button in the form.

do_action( 'anr_captcha_form_field' )

Adding the CAPTCHA via the WordPress editor

If the form can be edited via the WordPress editor, all you need to do is add the below short code to the page where you want the CAPTCHA check to appear in the form.

[anr-captcha]

How to verify the CAPTCHA

To verify the CAPTCHA is working use anr_verify_captcha(). This will return true on success. Otherwise it will return false. Below is an example:

if (anr_verify_captcha() ) {
     // Answer is right
     // process form
} else {
     // Answer is wrong
     // Show error or take other action
     // Do not process form
}