page templates

Page Templates & Post Templates

Last modified: June 15, 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.

The WordPress Template Hierarchy

WordPress does not load a random template for each page. It follows a fixed lookup order called the template hierarchy. For a standard page, WordPress checks for files in this order and uses the first one it finds:

  1. custom-template.php: any template assigned via the Page Attributes panel in the editor
  2. page-{slug}.php: e.g. page-about.php automatically applies to any page with the slug “about”
  3. page-{ID}.php: e.g. page-255.php for page ID 255
  4. page.php: the general page template
  5. singular.php: applies to both posts and pages if page.php does not exist
  6. index.php: the final fallback

Understanding this order prevents a common confusion: if page-about.php exists in your theme, WordPress will use it regardless of which template you select in the editor dropdown. Slug-based and ID-based templates always take priority over templates manually assigned in the editor.

Page Templates in Full-Site Editing Themes

If you are using a block theme with Full-Site Editing (FSE) enabled, the PHP template approach does not apply. Block themes store templates as HTML files in the templates/ folder, and you can create and edit them visually in the Site Editor under Appearance > Editor. The result is the same, a custom layout for specific pages, but the method is completely different. For classic themes with functions.php and style.css, the PHP file approach described in the steps below is the correct one.

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, create a new PHP file inside your active theme folder (or child theme folder, which is strongly recommended). Name it something descriptive, like page-full-width.php.

The Required Header Comment

Every page template must start with a PHP comment block containing a Template Name line. WordPress reads this comment on activation to register the template. Without it, the template will not appear in the editor dropdown:

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

A Minimal Working Template

After the header comment, add the structural WordPress functions your theme relies on. The simplest functional template copies the pattern from your theme’s existing page.php and strips what you don’t need:

<?php
/**
 * Template Name: Full Width
 */
get_header();
while ( have_posts() ) :
    the_post();
    the_content();
endwhile;
get_footer();
?>

In practice, copy your theme’s page.php into the new file, remove the sidebar call if you want a full-width layout, then adjust the HTML wrapper classes to match your CSS. Once the file is saved in the theme folder, create a new page in WordPress, open the Page Attributes panel on the right, and the template will appear in the Template dropdown.

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.

When to Use Slug vs ID

Use page-{slug}.php when the slug is stable and meaningful (for example, page-contact.php for your contact page). Use page-{ID}.php when you need to target a page that may have its slug changed later, since the page ID never changes. The ID method is also useful for dynamically generated pages where the slug follows a pattern that conflicts with other templates.

Practical Use Cases for Page Templates

  • No-sidebar landing page: Copy page.php, remove the get_sidebar() call, and name the template “Landing Page”. Use it for lead capture or sales pages that should not show navigation distractions.
  • Custom archive: Create a template that runs a custom WP_Query loop to pull posts from a specific category and display them in a grid format, without being a standard archive URL.
  • WooCommerce checkout alternative: Override the default checkout layout by applying a minimal template to the checkout page, stripping the header and footer for a distraction-free purchase flow.

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.