How to add Google reCAPTCHA in WordPress




Geniuswp show

Summary: Google reCAPTCHA is becoming popular since the day of its announcement. The performance of this product is not been evaluated yet because of its age.I have covered basic tutorial about how to code custom script with Google reCAPTCHA.In this tutorial i am going to explain how to add Google reCAPTCHA in WordPress engine. By using same method i added Google captcha in my blog. Have a look.UPDATE : We have updated the theme design and removed google ReCaptcha to address site loading issue but it still works the way is explained below.Table of ContentsStep 1: Register your blog to Google reCAPTCHA.Step 2: Add captcha in WordPress comment form.Where is functions.php located ?Step 3: Add captcha verification script.Further enhancement:Conclusion:Step 1: Register your blog to Google reCAPTCHA.First signup with your google account to Google reCAPTCHA site and register your blog here to get site key and secret key.Step 2: Add captcha in WordPress comment form.WordPress made an awesome feature called “hooks” which allow us to insert custom code in WordPress. You can do same by adding code to the particular file. In this case file would be comments.php.Open your functions.php and add these lines of code in end of bottom.Where is functions.php located ?Answer : function.php is placed in yoursite.com/wp-content/themes/theme_name/function.php. Better use filezilla to navigate and edit code properly.functions.php/*Add Google captcha field to Comment form*/add_filter('comment_form','add_google_captcha');function add_google_captcha(){ echo '';}/*End of Google captcha*/Step 3: Add captcha verification script.Open single.php from your theme main folder. This file is responsible for showing single post in your site. Since comment will be visible in posts ( if on page too then add those page code too) we need to add our extra verification which is Google recaptcha verification.Add following lines of code before the end of get_footer();.single.phpscript type="text/javascript">jQuery("#submit").click(function(e){ var data_2; jQuery.ajax({ type: "POST", url: "http://yourblog.com/wp-content/themes/yourtheme/google_captcha.php", data: jQuery('#commentform').serialize(), async:false, success: function(data) { if(data.nocaptcha==="true") { data_2=1; } else if(data.spam==="true") { data_2=1; } else { data_2=0; } } }); if(data_2!=0) { e.preventDefault(); if(data_2==1) { alert("Please check the captcha"); } else { alert("Please Don't spam"); } } else { jQuery("#commentform").submit } });script>Now we have added code to verify our captcha form. Here is PHP script which is responsible for calling Google API to determine the Spammer. create file and place code shown below and put it... You are listening to the topic about "How to add Google reCAPTCHA in WordPress", if you want to read the full article, please visit https://geniuswp.com or the link in the description.