Steps to Create Custom Page Template in WordPress
A page template is a specific type of template file features of page templates as follows
- Page templates are used to change the look and feel of a page.
- A page template can be applied to a single page, a page section1
- Page templates generally have a high level of specificity, targeting an individual page or group of pages. For example, a page template named page-about.php is more specific than the template files page.php or index.php as it will only affect a page with the slug of “about.”
Step 1: Creating a Custom Page Template for One Specific Page
you can create a template for a specific page. To create a template for one specific page, copy your existing page.php file and rename it with your page’s slug or ID:
For example, Our Booking page has a slug of ‘booking’ and an ID of 10. If your active theme’s folder has a file named page-booking.php or page-10.php, then WordPress will automatically find and use that file to render the Booking page.
Custom Page Template Path
To be used, specialized page templates must be in your theme’s folder (i.e. /wp-content/themes/my-theme-name/ ).
Step 2: Creating page templates for specific post types
To create a page template to specific post types, add a line under the template name with the post types you would like the template to support.
Step 3: Adding Header and Footer of default Theme to custom page template
If you want to use the default header and footer in your custom template add the following code to your template
For Header Add following code top of file in PHP
For Footer Add following code end of file in PHP
Step 4: Final template file
this is our final template file as follows
// Page code here...