Creating a custom page template in WordPress

The appearance of all the pages and posts that are created on a WordPress website is handled by a template file named page.php.

Basic knowledge of HTML CSS and PHP is required to create a custom template in WordPress.

Let us begin to add a custom page template to an existing theme.

Step 1) Navigate to your theme’s folder as shown below:

Screenshot (60)

Step 2) Open a text editor and add the following code.

 

<?php /* Template Name: TWSTemplate*/ ?>

Save as TWSTemplate.php 

Screenshot (61)

Step 3) Go to WordPress Admin Panel > Pages > Add New. You can see the new custom page template listed on the right side.

Screenshot (62)

Step 4) Create a new page and set its template to TWSTemplate. Once done, Publish it.

Screenshot (63)

You will see a blank page without any design as shown below. This shows that the custom page template in WordPress is successfully implemented

Screenshot (64)

 

The default appearance of the pages is generated by page.php file located in /wp-contents/themes/YOUR THEME/ folder. Open page.php and copy its code and customize.

Screenshot (65)

Screenshot (65)

Refresh the page to check your custom template.

Screenshot (67)

You are good to go!

Why I have created a custom page template when I could have easily edited the page.php file?

If page.php file is edited, all the pages across the website would show the changes.

In order to apply customized appearance on specific pages, custom page template in WordPress comes is useful.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s