Below, you’ll find a detailed guide on how to add the Contact Form 7 Captcha Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Contact Form 7 Captcha Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Contact Form 7 Captcha Plugin and the shortcodes it provides:
"Contact Form 7 Captcha is a robust WordPress plugin that enhances the security of your website by integrating a simple reCAPTCHA into your Contact Form 7. Prevent spam while maintaining user-friendliness."
- [cf7sr-simple-recaptcha]
Contact Form 7 Captcha [cf7sr-simple-recaptcha] Shortcode
The Contact-Form-7-Simple-Recaptcha shortcode is a unique tool that adds a reCAPTCHA field to your form. This shortcode generates a hidden input field for reCAPTCHA validation. It retrieves the site key from the plugin’s settings and creates a unique ID for each reCAPTCHA instance.
Shortcode: [cf7sr-simple-recaptcha]
Examples and Usage
Basic example – An uncomplicated usage of the shortcode that displays a simple reCAPTCHA form.
[cf7sr-simple-recaptcha /]
Advanced examples
Displaying a reCAPTCHA form with a unique ID. This can be useful when you want to differentiate between multiple reCAPTCHA forms on the same page.
[cf7sr-simple-recaptcha id="uniqueID" /]
Displaying a reCAPTCHA form with a custom class. This can be useful when you want to apply custom CSS styling to a specific reCAPTCHA form.
[cf7sr-simple-recaptcha class="customClass" /]
Combining both unique ID and custom class. This can be useful when you want to apply custom CSS styling to a specific reCAPTCHA form and differentiate it from others on the same page.
[cf7sr-simple-recaptcha id="uniqueID" class="customClass" /]
Please note, the ‘id’ and ‘class’ parameters are hypothetical and for demonstration purposes only. The actual shortcode provided does not accept any parameters.
PHP Function Code
In case you have difficulties debugging what causing issues with [cf7sr-simple-recaptcha]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('cf7sr-simple-recaptcha', 'cf7sr_shortcode');
Shortcode PHP function:
function cf7sr_shortcode($atts) {
global $cf7sr;
$cf7sr = true;
$cf7sr_key = get_option('cf7sr_key');
return '<div id="cf7sr-' . uniqid() . '" class="cf7sr-g-recaptcha" data-sitekey="' . esc_attr($cf7sr_key)
. '"></div><span class="wpcf7-form-control-wrap cf7sr-recaptcha" data-name="cf7sr-recaptcha"><input type="hidden" name="cf7sr-recaptcha" value="" class="wpcf7-form-control"></span>';
}
Code file location:
contact-form-7-simple-recaptcha/contact-form-7-simple-recaptcha/contact-form-7-simple-recaptcha.php
Conclusion
Now that you’ve learned how to embed the Contact Form 7 Captcha Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply