WordPress natively supports the setup of a personal or business contact form to allow site visitors to contact you directly. However the default WordPress theme doesn’t include a pre-installed contact form page.
In most cases WordPress users would turn to an external plugin to add the related Contact form, without realizing that it could cause its own series of problems. Plugins always serve as a weakness for hacking and hijacking opportunities, especially if they are out of date. Also, a blog can load slower and take more time to display on screen if too many plugins are running.
Therefore the best option is almost always to directly integrate a feature without the use of a plugin. That being said in this tutorial you will learn how to setup an integrated contact form within your WordPress install.
Contact Form Page Template
WordPress comes with the integrated use of custom templates for various pages which ultimately allows users the option to give each page unique appearances.
Creating a page template for the contact form is where we will start, as it provides the base appearance and function of the page.
To begin, copy the “Page.php” source file (for the active theme of the related WordPress blog or site) and rename the copy to “Contact.php”.
After that has been completed we need to add information into the beginning of the new “Contact.php” file to inform WordPress that it is a template. Input the following code at the very beginning of the file:
The “Contact.php” file should now resemble the following:
The section between the “<div id=”container”>” opening and closing tags needs to be added into your new “Contact.php” between the “get_header()” and “get_footer()” tags. Some themes may already have this information, or something similar, implemented- just make sure it is all there.
Adding In The Contact Form Code
Next we must add in the code to display the contact form and related information. In order to do this we are going to add to the pre-existing code. The following code needs to go between the “entry-content” opening and closing tags:
Contact Form Functions
The next bit of code will tell WordPress how to handle the contact form and will search for the admin’s email address and then send the related email where it belongs. Make sure to input the following code segment after the page template heading we added in the first step and the “get_header()” function:
What The Final Product Should Resemble
All in all if done correctly the entire “Contact.php” page we have created should look like the following bit of code (if you want to cheat you can simply copy this entire length of code instead of following the steps above):
Setting Up The Contact Page
To continue you simply need to design the contact page however you would like by either using the native WordPress page editor or an external html editing program. After loading the new file into your WordPress database you should be able to access it using the native WordPress visual editor.
In order to use the new Contact template we just set up we need to select it for use by the new contact page. In the admin panel/ WordPress dashboard simply navigate to “Appearance > Editor” and the page template in question (Contact.php) should now be included in the list. Take note that this is a page template and not the actual page.
In order to create the contact page you will need to set up a new page under the “Pages” tab (if you haven’t already designed a new page as mentioned in the beginning of this section). After the new page has been added you should be able to select the “Contact.php” template in the right hand side (the “Template” drop down menu under “Page Attributes”).
Note: Some options may be removed from sight to clean up the control panel, if you do not see a “Page Attributes” section simply click the “screen options” button in the top right of the page and ensure the check box next to “Page Attributes” is marked.
Wallah, you should now have a fully functioning contact page for use on your WordPress enabled blog or website.