Adding ReCaptcha for K2 on Joomla
Step 1. Add your site on Google ReCaptcha
- Go to Google ReCaptcha
- Log in with your Google account
- Go to My Account
- Click “Add a New Site” button and enter your website URL
- You will get public and private keys for that site
Step 2. Activate and configure ReCaptcha on K2
- Log in your Joomla admin panel
- Go to Components > K2 > Parameters > Comments
- Click on K2 Parameters button on top-right menu
- Open Comments tab and set “Active reCaptcha” to Yes
- Open Advanced tab, go to the Anti-Spam section and paste the previously obtained public and private keys
- Save!
If it doesn’t work yet, in my case, I have had to modify some code. Open this file:
components/com_k2/views/item/view.html.php
and update the new repository URL:
//$document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js'); // Old URL
$document->addScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js'); // New URL
Also, in the same file, I needed to remove some lines (see the commented lines):
$js = '
function showRecaptcha(){
Recaptcha.create("'.$item->params->get('recaptcha_public_key').'", "recaptcha", {
theme: "'.$item->params->get('recaptcha_theme', 'clean').'"
});
}
//$K2(window).load(function() {
showRecaptcha();
//});
';