How to Create a Simple Contact Form with Captcha for WordPress

There are many contact forms available for WordPress but most use a third party captcha service. The contact form on my website uses the following custom plugin that has a basic math captcha, no third party required.

Why Use Simon’s simple contact form Plugin?

  • ✅ Easy to Use: Just install and use the shortcode [simple_contact_form] .
  • 📱 Mobile-Responsive: Works great on all screen sizes.
  • 🔒 Built-in Spam Protection: Includes a simple math captcha.
  • ⚡ Lightweight: No bloat, just a clean and functional contact form.

How to Install the Plugin

  1. Step 1: Open your WordPress Admin Dashboard and go to Plugins > Plugin File Editor or use an FTP client.
  2. Step 2: Create a new file in the wp-content/plugins folder called simons-simple-contact-form.php
  3. Step 3: Copy and paste the following PHP code into that file:
    [simple_contact_form]
     to display the form.
    Version: 1.0
    Author: Simon Ward
    Author URI: https://simonward.net
    License: GPLv2 or later
    License URI: https://www.gnu.org/licenses/gpl-2.0.html
    */
    
    // Prevent direct access
    defined('ABSPATH') or die("No direct access allowed");
    
    function scf_form_shortcode() {
        session_start();
        $_SESSION['captcha_num1'] = wp_rand(1, 9);
        $_SESSION['captcha_num2'] = wp_rand(1, 9);
        $_SESSION['captcha_answer'] = $_SESSION['captcha_num1'] + $_SESSION['captcha_num2'];
        
        ob_start();
        ?>
        
    Message sent successfully!
    Captcha incorrect. Please try again.
    \r\n" . "Reply-To: " . esc_attr($email); wp_mail($to, esc_attr($subject), esc_textarea($message), $headers); $_SESSION['scf_success'] = true; } } add_action('wp', 'scf_handle_form_submission');
  4. Step 4: Go to Plugins in your WordPress admin and activate Simon's Simple Contact Form.
  5. Step 5: Create or edit a page/post and add the following shortcode where you want the form to appear:
    [simple_contact_form]
    

You’re Done!

Your simple, secure, mobile-ready contact form is now live on your site. Messages will be sent to the admin email address configured in your WordPress settings.

Scroll to Top