To implement Cloudflare’s Turnstile CAPTCHA in WordPress, follow these steps:
There are several ways to integrate Turnstile into your WordPress site. The easiest is by using a plugin. Here’s how:
Add the following Turnstile API script in your WordPress theme’s header.php
file:
Edit your WordPress theme (you can do this through the theme editor or by using FTP/SSH).
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
In the form where you want to display Turnstile, add the following code inside the form’s <form>
tags:
<div class="cf-turnstile" data-sitekey="YOUR_SITE_KEY"></div>
Replace "YOUR_SITE_KEY"
with the actual Site Key from Cloudflare.
On the form submission handler (usually in the functions.php
file or the form plugin’s PHP file), verify the Turnstile token. You will send the cf-turnstile-response
token to Cloudflare for verification. Use a code snippet like this:
function verify_turnstile_token($token) {
$secret = 'YOUR_SECRET_KEY'; // Replace with your Cloudflare secret key
$response = wp_remote_post('https://challenges.cloudflare.com/turnstile/v0/siteverify', [
'body' => [
'secret' => $secret,
'response' => $token,
],
]);
$body = wp_remote_retrieve_body($response);
$result = json_decode($body);
return $result && $result->success;
}
// Use this in your form validation logic:
if (!empty($_POST['cf-turnstile-response'])) {
$token = sanitize_text_field($_POST['cf-turnstile-response']);
if (verify_turnstile_token($token)) {
// Proceed with form submission
} else {
// Handle invalid Turnstile response
}
} else {
// Handle missing Turnstile response
}
This ensures Turnstile is verified on the backend, protecting against spam and bots.
Would you like help with any specific aspect of this implementation?
🔍 How to Open DevTools You can open DevTools in several ways: Right-click on any…
Model Context Protocol (MCP) is revolutionizing how AI applications connect with external tools, APIs, and…
The Small Business Innovation Research (SBIR) program offers a vital pathway for startups to secure…
Looking to start a business in California? This guide explores 10 high-potential business ideas—from real…
UNited States https://www.glassdoor.co.in/Overview/Working-at-Prefr-co-EI_IE7010540.11,19.htm https://www.ambitionbox.com/overview/prefr-dot-co-overview https://rocketreach.co/prefrco-management_b7c95a7ec0ee0ee2 https://www.signalhire.com/companies/prefr-co https://www.zoominfo.com/c/prefrco/557658591 United Kingdom https://www.yellowtom.co.uk/reviews/1417493 Canada https://www.pandia.com/ca/oshawa-on/graphic-design Singapore https://talenttribe.asia/companies/prefr-co India…
We are seeking a skilled and motivated Blockchain Engineer to join our team. In this…