Select Page

This article is intended to help the user of Skt NURCaptcha WordPress plugin to enable and use a Google’s reCAPTCHA anywhere on the pages of a WordPress site. It suposes you are familiar to PHP and WordPress programming.
Version 3.4.3+ of the plugin is required, for the instructions given here work properly

First step – enable Google’s reCAPTCHA widget

In order to get rendered in a page, reCAPTCHA requires a call to a script provided by Google to be inserted within the <head></head> tag on that page. To get this done, you may go to the Settings page of Skt NURCaptcha (in the back end of your site) and scroll down till you find “enable reCAPTCHA on selected front pages“. Then click on the button “Toggle selector” to see a list of your site’s pages, each one sided by a small checkbox. Select the pages where the reCAPTCHA should show up and then click on “Update options”.

If you want to display the captcha on a sidebar widget or on the footer, and not only on selected pages, you must enable it sitewide. To do that, just drop anywhere in your theme’s functions.php file the line below. It calls a function to provide the insertion of that Google’s small piece of code into the ‘head’ tag of every and all pages at the front side of your site:

add_action('wp_head', 'skt_nurc_sitewide_enable_captcha');

Second step – get reCAPTCHA rendered in a page

To get the reCAPTCHA rendered in a front page on your site, supposed you have gone successful through step one, you will need a special “div” block to be placed anywhere within a form on that page. Skt NURCaptcha has a function that produces the proper html code for that block, with the attributes that will render the reCAPTCHA the way you selected on the plugin’s settings page. So, to get this second step done, you may use a call to this function within the PHP code of your form, by simply adding this line:

<?php nurcRecaptcha(); ?>

Keep in mind that this line must be inserted somewhere within the form intended to be protected by the reCAPTCHA. That’s say you must find a place for it in between a tag-pair <form></form>, otherwise it will not work, though displaying on the page.

Third step – verifying the user’s response

The use of a captcha only makes sense if you have the response of the user verified by your code. So, you must add this code to the landing page (see form’s action=”” attribute), at the point where the $_POST[ ] data are being verified:

$result = nurcResponse();
if ($result->is_valid) {
// the user passed through the reCAPTCHA - so go on with your code...
// user's response is wrong - so, stop and go back to the form, with an error message in $result->error

These steps will extend the reCAPTCHA protection to any form at any page in your site, provided you can add the code lines to the appropriate places within your theme or plugin. They work fine with Skt NURCaptcha version 3.4.3+, connected to the new version of Google’s reCAPTCHA (since dec/2014).