Web Security

What is a WordPress template and how to create a custom page template


Sushil Pradhananga

Published On : 

February 26, 2023

Create a custom page template in wordpress CMS

In WordPress, a template is a file that controls the overall structure and layout of a specific type of page or post of your responsive WordPress Theme

WordPress uses templates to display content dynamically/statically, allowing you to control the design of your WordPress theme and functions. WordPress templates are written in PHP, HTML, and CSS code, and they include various html and PHP tags and functions that allow customization of the appearance and behavior of your WordPress theme.

WordPress has several pre-built responsive templates included in its default themes, including:

  • Index.php – It is used to display your website’s main landing page may it be any blog post or any custom page.
  • Page.php – It is used to display the content of pages that are created from the backend of WordPress. Pages content is dynamically pulled in this template through the PHP function.
  • Single.php – It is used to display the content of blog posts created from the WordPress backend. Post content is dynamically pulled through PHP function.
  • Archive.php – It displays a list of blog posts by category, date, or tag.
  • Header.php and footer.php – These files display your website’s header and footer sections. It is pulled dynamically under any index.php, page.php, or single.php file so that the header and footer section of the website is maintained uniformly from a single section.

You can also create templates to further customize your website’s design and functionality. Custom templates can be created using WordPress’s built-in template hierarchy or by using page builders and other third-party tools.

How to create a custom WordPress page template using the built-in hierarchy of your WordPress theme:

Creating a simple template file in a WordPress theme involves creating a new file in your theme folder and adding some basic code to it. Here is a step by step guide:

  1. Open your favorite code editor (Notepad ++, Dreamweaver, sublime text, etc.) and create a new file. Save the file with a name that corresponds to the template you want to create. For example, if you want to create a template for your gallery page, you can name the file “page-gallery.php”.
    At the top of your file, add the following code:
php header code

This code defines the template name and loads the header.php file, which contains the header section of your website.

2. Next, add the code that displays the content of your custom template. For example, if you want to display a title and show content add the following code:

php code to build custom page

3. Finally, add the code that loads the footer section of your website:

php footer code

4. Save the file and upload it to your theme folder. You can find the theme directory in the

file path

5. To assign the new template to a specific page, go to the WordPress admin area and edit the page to which you want to assign the template. In the Page Summary area, there is a template dropdown where you can choose the template you just created.

sample wordpress page template

That is it, now when you visit this page, it will load the page with the template you created instead of the default WordPress theme.

Humming Web

Let’s talk about your business goal and align the solution we provide with our digital marketing services.

FREE strategy call

© Humming Web. All Rights Reserved