How to create a Custom Page Template in WordPress

If you have worked with WordPress you have probably seen different page designs being used on one website. You as well probably do not want all your pages to look the same, right? One way of creating something different is creating a custom page template where you are free to play around and create a page which you really need and want.

A great example of a custom page template is a contact page where you can place your information, a contact form and maybe a Google Map so you can show your visitors the location of your business. Another example is a page where you will show the list of your authors, team members or staff. Or maybe you want a special page where you will list the most popular comments? We can go on but you get the point – with custom page templates you are free to create anything you want.

To make the best out of your custom pages, you will have to know your way around the code. Of course, you are free to copy the code from another page you are using and modify it or take a page from another free theme like Twenty Fifteen, but you will still have to know your way around HTML and PHP if you want your new page template to have its functionality.

So far, we have to leave that part to you; in this article, we’re going to show you how to create a custom page template and how to add basics into it.

Before we scare you off by mentioning those scary abbreviations like HTML and PHP, you must know that creating a basic temple is very easy. Just follow these few steps and you’ll have your own custom template in a minute:

  1. Unless your theme already has a template folder, you should create one where you will store your new custom page templates. In your public_html folder, create a folder “Templates” or skip this step if you already have one
  2. Create a new file and name it something like this: my-custom-page-template.php
  3. Open the file and paste the following code into it:
  4. If you are modifying an existing page template from your theme, we suggest you do that in your child theme.

  5. Save changes and your page is created

After you have created your new template, you will find it under Page Attributes in your WP admin. Simply choose the page template you have created and the code from that page will be executed. Of course, in the example above there is no code to be executed so you have to start working on your page design.

Although you are creating a custom page, you will still probably want your header, footer and maybe a sidebar to be included in the new page. To make those a part of your new page, you will need to paste the following code in my-custom-page-template.php:

After this point, everything’s up to you. If you are creating a contact page, you may place HTML forms and buttons by yourself, copy them from another page and customize to your needs or install a plugin which will create contact form for you so you can simply paste a shortcode into your new page.

First name:

Last name:

If you want a Google Map, see how to generate a code for location of interest and paste into your new page template or do that in a second by using Google Maps Widget.

Take the creative side out of you and start customizing your new page template.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *