How to add a contact form in WordPress without any plugins

If you want to add a contact form in your WordPress website without using any plugin, this guide will help you do this easily.

The contact form is an essential element of every website, whether built using WordPress or any other CMS. The problem is that when you add a contact form plugin, it loads some default scripts and link tags on all website pages.

As we know the more scripts and files linking to our page, the more time it will take to load. Sometimes, these plugins are loading external CSS and JS files causing the web page to load even slower.

So, How do we get rid of these slow-loading scripts and files?

In this tutorial, you will learn how to add a custom contact form without any plugins. We will cover these topics in this article:

How to add a contact form in WordPress without any plugin
How to add a contact form in WordPress without any plugin

What is a contact form?

A contact form is a simple form that usually gets input from the user (Name, Email, Phone, and Message) for the sake of communication. You can collect different details about a visitor who is interested in contacting you for some reason.

Most commonly, a contact form consists of three input fields: Name, Email, and Message. You can adjust the input fields according to the nature of the website accordingly.

Advertisement

Why do we use a contact form on our website?

There are several reasons for using a contact form on our website. From providing convenience to the visitor to the comfort of website admins, it serves a lot as:

Easy Communication

A contact form creates an easy and convenient communication channel between visitors of the website and the site admin. The visitor doesn’t have to find your email address and then compose a message to contact you. Instead, they can just fill up their details and the rest is handled by this form.

Spam Protection

If you are using a contact form on your WordPress website, it will prevent spammers from bursting messages in your inbox. Moreover, in this article, you will learn to add a custom contact form with a built-in math captcha.

Organized Information

Organizing contact details of visitors or clients can be an issue if you are dealing with them directly. By using a contact form, you can easily get organized information in your email inbox or you can create a separate page to display all contact form entries.

Security

Without a contact form, you will be exposing your business email to cyber and phishing attacks. You can prevent all these risks, by just adding a simple contact form with necessary input fields.

How to add a custom contact form on our WordPress website?

As we are not using any plugin to add this contact form, so you will have to be ready to modify some files in your theme. But don’t worry, I will get you through this with ease and matter of seconds. Just follow these steps with care and don’t forget to take a backup of your WordPress website in case of any problem.

Step 1: Adding HTML and JS to your Web Page

Create a new page and name it “Contact Us” or whatever you want to.

Click “Edit” and go to the page editor.

Click the Plus icon in the left corner and search for the HTML element.

Copy and Paste this HTML + JS Code into this HTML element.

The code marked in Orange color will be updated according to your file location. (Explained in the next step)

Advertisement

Step 2: Adding PHP Handler file to your WordPress theme

Once you have made changes to the Contact Us page, the next step is to handle the data sent by this form. We will use a simple mail function to send this data to your email address. For this step, you have to install a plugin to access theme files and create a new one.

(You can uninstall this plugin after we are done modifying the files)

  1. Install a new Plugin “File Manager“.
  2. Click on it after installing and activating it from the left sidebar.
  3. Go to “public_html“, and you will see all files of WordPress.
  4. Create a New file by clicking on the file icon in the top left corner of the file manager interface.
  5. Name the file as “contact-form.php
  6. Copy and Paste this code into that PHP file.
  7. The file should have this path “public_html/contact-form.php

UPDATE YOUR EMAIL IN THE ABOVE CODE

Save this file and test by viewing the contact form in a browser window. By default, I have added a math captcha in this code to prevent spam entries.

Step 3: Testing your custom contact form with Gmail

After doing the above two steps, test your form thoroughly on different browsers to make sure it works fine. Sometimes, email is received in spam because of email reputation. To avoid this, configure SMTP on your website for secure and successful email delivery.

Conclusion and Results

By following these simple steps, you will have a simple contact form without any plugins in your WordPress website. You can update the code if you want to add or remove some fields with the help of a developer or chatGPT.

Scroll to Top