Welcome to Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy

Create Custom Page Template in WordPress

Steps to Create Custom Page Template in WordPress

A page template is a specific type of template file features of page templates as follows

  1. Page templates are used to change the look and feel of a page.
  2. A page template can be applied to a single page, a page section1
  3. 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:

  • page-{slug}.php
  • page-{ID}.php

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.

				
					<?php
/*
Template Name: Booking Details Page
Template Post Type: post, page, event
*/
// Page code here...

				
			

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

				
					get_header();
				
			

For Footer Add following code end of file in PHP

				
					get_footer();
				
			

Step 4: Final template file

this is our final template file as follows

				
					<?php
/*
Template Name: Booking Details Page
Template Post Type: post, page
*/
get_header();
?>

// Page code here...


<?php 
get_footer();
				
			
Custom Page Template file in WordPress

Drop your queries

Table of Contents

Have A Project In Mind? Let's Get To Work