In WordPress, page templates are a specific type of template file that are used for a specific page or group of pages. A page template only applies to pages, not for other content types. The page templates are used to change the look and feel of the pages. If you want to make a page different from other pages, create a custom page template.
This tutorial shows you how to create custom page templates that can be assigned to the pages from administrative panel. Custom page template allows you to make the different layout for different pages.
When the browser requests a page, WordPress selects which template will use to render this page. As per the WordPress Template Hierarchy, page template files are looked like the following order.
When you want to use a custom template globally for multiple pages, then you can be assigned the custom page template to any pages from page add and edit screen. Follow the simple two steps mentioned below to create a custom page template for global use.
Create Template File:
Create a PHP file (page-template-full.php
) and placed it in active theme directory (/wp-content/themes/theme_name/
). It will a best practice to group all the template file with a common filename prefix (page-). In this file, write an opening PHP comment to specify the template name.
<?php
/**
* Template Name: Custom Page Template
*/
Rest of the code will be written after this comment block.
Assign Template to Page:
Go to the Page » Add or Page » Edit screen in your admin dashboard. On the right-hand side, you’ll see the custom template is available in the Template drop-down menu under the Page Attributes section. By selecting the custom template, it can be assigned to the respective page.
The specific custom page template is used for a particular page. To create a specific page template, go to the active theme directory (/wp-content/themes/theme_name/
) => copy the existing page.php
file and rename it with the specific page slug or ID.
For example, you want to customize your About Us page with a custom page template. So, custom About Us page template file name would be page-about-us.php
or page-10.php
. WordPress will automatically render that file when About Us page is requested by the browser.
Do you want to get implementation help, or enhance the functionality of this script? Click here to Submit Service Request