Add Captcha plugin to a custom form on my Wordpress website

Follow the instructions below in order to add Captcha plugin to your custom PHP or HTML form:

  1. Install the Captcha Pro plugin and activate it.
  2. (Optional) If you want to use own settings for your custom forms (for example, for your contact and sign up forms), please follow steps below:
    • Open "functions.php" file of your theme in the edit mode;
    • Add the following lines to the end of the file:
      function add_my_forms( $forms ) {
          $forms['form_slug']   = "Form Display Name";
          $forms['form_2_slug'] = "Form 2 Display Name";
          return $forms;
      add_filter( 'cptch_add_form', 'add_my_forms' );
      Please don't use the next form slugs since they are predefined by plugin settings: general, wp_login, wp_register, wp_lost_password, wp_comments, bws_contact, bws_subscriber, buddypress_register, buddypress_comments, buddypress_group, cf7_contact, woocommerce_login, woocommerce_register, woocommerce_lost_password, woocommerce_checkout.
    • Save file changes;
    • Go to the "Settings" tab on the plugin settings page (Admin Dashboard -> BWS Panel -> Captcha Pro); If everything is OK, you will see new tabs with labels which you specified in the "cptch_add_form_tab" hook call function.
    • Switch to new tabs and configure form options on them as you need;
    • Click "Save changes"; In case when you don`t want to use own settings for displaying the CAPTCHA in your custom form, the settings from "General Options" tab from the plugin settings page will be used.
  3. Open the file with the form (where you would like to add CAPTCHA);
  4. Find a place to insert the code for the CAPTCHA output;
  5. Insert the following lines:
    <?php echo apply_filters( 'cptch_display', '', 'my_contact_form' ); ?>

    In this example, the second parameter is a slug for your custom form. If you don`t use the custom form settings (see point 2 of this instructions) you can leave it empty:

    <?php echo apply_filters( 'cptch_display', '' ); ?>
  6. After that, you should add the following lines to the function of the entered data checking:
    <?php $error = apply_filters( 'cptch_verify', true );
    if ( true === $error ) { /* the CAPTCHA answer is right */
        /* do necessary action */
    } else { /* the CAPTCHA answer is wrong or there are some other errors */
        echo $error; /* display the error message or do other necessary actions in case when the CAPTCHA test was failed */
    } ?>
    If there is a variable in the check function responsible for the errors output, you can concatenate variable $error to this variable. If the 'cptch_verify' filter hook returns 'true', it means that you have entered the CAPTCHA answer properly. In all other cases, the function will return the string with the error message.
Have more questions? Submit a request