How To Create Page Template In WordPress

In this article, We are going to see How To Create a Page Template In WordPress.

There are three types to create page templates in WordPress.

  1. Custom Page Templates for Global Use
  2. Custom Page Template for One Specific Page
  3. Page Templates for Specific Post Types

1. Custom Page Templates For Global Use

In which template can be used globally on any page or multiple pages.

Step-1: Create a new PHP file and add the below code in this file.

<?php
/*
Template Name: PageTemplate 
*/ 
?>
<h1><?php wp_title(''); ?></h1>
<p>Creating a Custom Page Template for Global Use</p>

The following information is required:

  1. Template Name – This needs to be unique to your template.

Please check the below video:

2. Custom Page Template For One Specific Page

In which template is used for only a specific page.

Step-1: Create a page.php file and rename it width your page’s slug or ID:

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

For example, Your example page has a slug of ‘example’ and an ID of 3. If your active theme’s folder has a file named page-example.php or page-3.php, then WordPress will automatically find and use that file to render the example page.

3. Page Templates For Specific Post Types

In which template is used for only a specific page type.

Step-1: Create a new PHP file and add the below code in this file.

<?php
/*
Template Name: SpecificPageTemplate
Template Post Type: movies
*/
?>
<h1><?php wp_title(''); ?></h1>
<p>Creating page templates for specific post types</p>

The following information is required:

  1. Template Name – This needs to be unique to your template.
  2. Template Post – need to add specific post type.

Please check the below video:

Thank You, hope you guys found something useful.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories