Adding a contact form to your WordPress website is essential for allowing visitors to get in touch with you. Whether it’s for inquiries, feedback, or support, a contact form makes communication easy and professional. In this guide, we’ll walk you through the steps to add a contact form to your WordPress site using plugins and custom code.
Why Add a Contact Form?
- Improve User Experience:
A contact form provides a convenient way for visitors to reach out without leaving your site. - Reduce Spam:
Contact forms can include CAPTCHA or other spam protection measures. - Professional Appearance:
A well-designed contact form enhances your site’s credibility. - Collect Information:
You can customize fields to gather specific information from users.
How to Add a Contact Form to WordPress
Method 1: Using a Plugin (Easiest Option)
Plugins are the simplest way to add a contact form to your WordPress site. Here are two popular options:
Option A: Using WPForms
- Install and Activate WPForms:
Go to Plugins > Add New, search for “WPForms,” and install the plugin. - Create a New Form:
- Go to WPForms > Add New.
- Choose a template (e.g., “Simple Contact Form”).
- Customize the form fields, such as name, email, and message.
- Configure Form Settings:
- Set up notifications to receive emails when someone submits the form.
- Enable CAPTCHA or other spam protection features.
- Add the Form to Your Site:
- Copy the shortcode provided by WPForms.
- Paste the shortcode into a page or post where you want the form to appear.
- Publish the Page:
Save or update the page to make the form live.
Option B: Using Contact Form 7
- Install and Activate Contact Form 7:
Go to Plugins > Add New, search for “Contact Form 7,” and install the plugin. - Create a New Form:
- Go to Contact > Add New.
- Use the default form template or customize the fields using the provided tags.
- Configure Form Settings:
- Set up the email address where you want to receive submissions.
- Customize the email subject and message.
- Add the Form to Your Site:
- Copy the shortcode provided by Contact Form 7.
- Paste the shortcode into a page or post where you want the form to appear.
- Publish the Page:
Save or update the page to make the form live.
Method 2: Using a Page Builder
If you’re using a page builder like Elementor or Divi, you can add a contact form directly through the builder.
Option A: Using Elementor
- Install and Activate Elementor:
Go to Plugins > Add New, search for “Elementor,” and install the plugin. - Edit a Page with Elementor:
- Open the page where you want to add the form.
- Click Edit with Elementor.
- Add a Contact Form Widget:
- Drag and drop the Form widget onto the page.
- Customize the form fields, design, and settings.
- Publish the Page:
Click Update to make the form live.
Option B: Using Divi Builder
- Install and Activate Divi Theme or Plugin:
If you’re using the Divi theme or plugin, you already have access to the Divi Builder. - Edit a Page with Divi Builder:
- Open the page where you want to add the form.
- Click Enable Visual Builder.
- Add a Contact Form Module:
- Add a new row or section.
- Insert the Contact Form module.
- Customize the form fields, design, and settings.
- Publish the Page:
Click Save to make the form live.
Method 3: Using Custom Code (Advanced)
If you prefer to add a contact form without using a plugin, you can do so by adding custom code to your theme.
Step 1: Create a Contact Form in HTML
- Create a New File:
Open a text editor and create a new file namedcontact-form.php
. - Add the Following Code:
<form action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
<p>
<label for="name">Name:</label>
<input type="text" name="name" required>
</p>
<p>
<label for="email">Email:</label>
<input type="email" name="email" required>
</p>
<p>
<label for="message">Message:</label>
<textarea name="message" required></textarea>
</p>
<p>
<input type="submit" name="submit" value="Send">
</p>
</form>
Step 2: Add PHP Code to Process the Form
- Add the Following Code to
contact-form.php
:<?php
if (isset($_POST['submit'])) {
$name = sanitize_text_field($_POST['name']);
$email = sanitize_email($_POST['email']);
$message = esc_textarea($_POST['message']);
$to = 'your-email@example.com';
$subject = 'New Contact Form Submission';
$headers = "From: $name <$email>";
if (wp_mail($to, $subject, $message, $headers)) {
echo '<p>Thank you for your message!</p>';
} else {
echo '<p>Something went wrong. Please try again.</p>';
}
}
?>
Step 3: Add the Form to Your Theme
- Upload the File:
Use an FTP client or your hosting control panel to uploadcontact-form.php
to your theme folder. - Add the Form to a Page or Template:
Use the following shortcode to display the form:phpCopy<?php include(‘contact-form.php’); ?>
Best Practices for Contact Forms
- Keep It Simple:
Only ask for essential information to avoid overwhelming users. - Use Spam Protection:
Add CAPTCHA or honeypot fields to prevent spam submissions. - Test Your Form:
Ensure the form works correctly and that you receive submissions. - Make It Mobile-Friendly:
Ensure the form is responsive and easy to use on all devices. - Include a Privacy Policy:
Add a link to your privacy policy to comply with data protection regulations.
Final Thoughts
Adding a contact form to your WordPress site is a straightforward process that can greatly enhance your site’s functionality and user experience. Whether you use a plugin, a page builder, or custom code, a well-designed contact form is a must-have for any website.
Have you added a contact form to your WordPress site? Which method did you use? Share your experiences in the comments below! If you have any questions, feel free to ask—we’re here to help!