page templates

Page Templates & Post Templates

Last modified: May 25, 2026

Fiverr freelancers

WordPress gives every page on your site a default layout based on your theme’s template files. But sometimes the default layout is not what you need. A page template lets you override that default and apply a completely different layout or functionality to specific pages, without editing your theme’s core files.

Post templates extend this same idea to posts and custom post types. Since WordPress 4.7, you can create templates that apply not just to pages but to any post type you have registered. This guide covers what page templates and post templates are, how to create them in PHP, and how to target specific pages or post types with a single template file.

If you are using a page builder like Elementor or a block theme, your builder may handle templates through its own interface. The PHP method covered here applies to classic themes and child themes, and gives you the most direct control over what gets rendered.

Show More

* This button will show the rest of the post and open up an offer from a vendor

What is a Wordpress Page Template?

A page template is created to change the way a specific kind of page is built and how it looks. For example: if you have a cooking blog, you might have an about page which would consist of a title and some text. However, you might want to have a page that shows all the recipes that have potatoes in them. In order to do that you would have to code the page to do that by pulling in all those recipes, and that would need to be done on a separate file.

Another very popular example is a full width template. Instead of creating a page with a sidebar, you might want a full width page.

So when creating the page in the admin, you would see a drop down menu allowing you to choose from all the templates that exist in your theme.

It would look something like this:

post template

Post Template & CPT Template

As you probably noticed, in the image above it says “post template” and not “page template”. That’s because since WordPress 4.7, templates are available for all post types, not just pages.

This matters if you are working with custom post types (CPTs). If you have a “Recipe” CPT or a “Portfolio” CPT registered on your site, before 4.7 you could not easily apply different layouts to individual posts within those types without editing template files directly. From 4.7 onward, you can create a PHP template file that targets one or more post types and let WordPress display a selector in the editor, the same way page templates work.

The key difference from page templates: a post template declared with Template Post Type in its header comment can apply to multiple post types at once. A page template with just Template Name only applies to pages. The following sections cover the exact code for both.

How to Create a Page Template?

First of all you need to create a new file within your theme and call it – page-templatename.php

The Code:

At the top of your page add this:

<?php
/**
 * Template Name: Full Width
*/

Now if you save your file and go create a new page and open the drop down menu, you will see your newly created template. Now all you need to do is code it to do what you want. In general, you would probably want to copy your page.php file into the newly created file and start from there.

Post Type Templates

As mentioned above, as of version 4.7 you can create custom templates for any type of post type, no matter if it’s a regular post or a post type you created specifically for your site. Unlike regular page templates, here you can reuse the same template on various post types within the same file. So just name you file something that will make sense when you look at it later and add the following to your new file:

<?php 
/*
Template Name: Full-width layout
Template Post Type: post, page, recipe, movie
*/

 

Here we have 2 lines:

The first is the same as the page template, this is the name that will appear in the menu drop down. The second row tells us which post types can use this template, so just decide which post types can use the template and add a comma between them.

Create a Custom Template for a Specific Page

Assuming you don’t want to create a template that can be reused, you want this template to be used on a specific page and that’s it, this is what you need to do:

Copy your page.php file, create a new file and rename it like this:

  1. page-{slug}.php
  2. page-{ID}.php

So if your slug is named aboutyou name it: page-about.php.

If your page ID is 255, you name the file: page-255.php.

Final Word: WordPress Page Templates and Post Templates

WordPress’s template system is one of the more straightforward parts of theme development once you understand the pattern. A page template changes how a specific page looks without affecting anything else. A post type template extends that control to any registered post type. And the slug- or ID-based template lets you target a single specific page automatically, without a dropdown.

A few things to keep in mind:

  • Always work in a child theme if you are modifying an existing theme. Adding template files directly to a parent theme means your work gets overwritten on the next theme update.
  • The template hierarchy matters. WordPress checks for template files in a specific order. If you create page-about.php, it takes priority over any page template assigned in the editor. Understanding this prevents confusing situations where your chosen template does not take effect.
  • Not comfortable with PHP? Page builders like Elementor and full-site editing block themes handle template creation through a visual interface. The PHP method gives you the most direct control, but it is not the only option.

Start with the simplest approach that meets your needs. Copy page.php, strip out what you do not want, and build from there.

Recap:
Save 4 Later
Email liked links to yourself

    Stay Updated with WordPress Insights

    Get the latest WordPress tips, theme reviews, and industry deals delivered to your inbox.