page templates

Page Templates & Post Templates

Last modified: August 10, 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 touching your theme’s core files or adding CSS hacks to make one page look different from all the others.

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.

Troubleshooting: Why Your Template Is Not Showing Up

Creating the template file and assigning it in the editor are only two of the steps that need to go right. Here are the most common reasons a custom template does not appear or take effect:

  • Missing or malformed header comment: WordPress only registers template files that contain a valid Template Name: line in a PHP comment block at the top of the file. If that comment is missing, misspelled, or placed inside the body of the file rather than at the top, WordPress will not see the template at all. The dropdown in the editor will simply not show it.
  • File is in the wrong folder: Template files must be placed directly inside your active theme folder (or child theme folder), not inside a subfolder. A file at wp-content/themes/my-theme/templates/page-full-width.php will not be registered. It needs to be at wp-content/themes/my-theme/page-full-width.php.
  • Caching is showing the old layout: If you assigned the template and the page still looks the same, check your caching plugin. W3 Total Cache, WP Rocket, and similar tools cache page output. Clear the cache after switching templates.
  • Slug-based template is taking priority: If a file named page-{slug}.php exists in your theme for that page’s slug, WordPress will use it instead of whatever you selected in the editor. The editor-assigned template only wins if no slug or ID match exists higher up the hierarchy.
  • Template is in a parent theme, not a child theme: WordPress checks the child theme folder first. If both the parent and child theme have a file with the same name, the child theme version wins. Parent theme templates still work as fallbacks, but if you expect the child theme to override them, confirm the file is actually in the child theme directory.

To confirm which template file WordPress is actually loading, install the Query Monitor plugin. It shows the template file path for the current page under the Template tab in the admin toolbar.

When to Use Each Template Method

There are three distinct ways to apply a custom layout to a WordPress page, and each fits a different situation:

  • Page template (dropdown in editor): Use when you want a reusable layout that any page can be assigned to. Good for site-wide layout options like “No Sidebar” or “Landing Page.” The person managing the site can assign it without touching code.
  • Slug-based template (page-{slug}.php): Use when exactly one page needs a specific layout and the slug will not change. No editor assignment required. Good for a permanent contact or about page where you want no risk of someone accidentally switching the template.
  • ID-based template (page-{ID}.php): Use when you need slug-based targeting but the slug might change. The page ID never changes, so the template stays locked to that specific page regardless of what the URL becomes.

For post types rather than pages, use the Template Post Type header line combined with Template Name. That is the only reliable way to create a template that appears in the editor dropdown for custom post types.

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 changes what WordPress renders for a specific page, letting you give one page a completely different layout from everything else on your site. The dropdown under Page Attributes in the WordPress editor lists every template file your theme has registered, and selecting one swaps the default layout for that page only.

In practice, here is where this matters:

  • Full-width landing pages: Your theme’s default layout probably includes a sidebar. For a lead capture page or promotional page, you want the full browser width without a sidebar and possibly without the standard header. A page template strips those out for just that one page.
  • Portfolio or case study pages: A portfolio page typically needs a grid layout and a custom query to pull in project posts, which the default page.php cannot provide. A dedicated template file handles the custom loop and layout.
  • Client-specific pages: If you are building a multi-section site where one segment has a different color scheme or header, a page template can load a different stylesheet or header file for pages assigned to that template.
  • WooCommerce checkout overrides: You can create a minimal WordPress page template that strips the site header and footer for a distraction-free checkout experience, then apply it to the WooCommerce checkout page.

You would see the template selector in the WordPress editor here:

WordPress page template dropdown in the Page Attributes panel

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

Copy your page.php file, create a new file and rename it using one of these patterns:

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

If your slug is about, name the file page-about.php. If your page ID is 255, 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 specific page but its slug might change later, since page IDs never change in WordPress.

Practical Use Cases for Specific-Page Templates

  • No-sidebar landing page: Copy page.php, remove the get_sidebar() call, and save it as page-landing.php. Every page with that slug gets the full-width layout automatically.
  • Custom archive page: Build a template that runs a custom WP_Query loop pulling posts from a specific category into a grid layout, attached to a specific slug like page-recipes.php.
  • Distraction-free checkout: Create a minimal template without header navigation and save it as page-checkout.php. WooCommerce’s checkout page typically uses the slug “checkout,” so this template applies automatically.
  • Client presentation pages: For pages that serve as client-only dashboards or private previews, a slug-based template can load a different header and hide the main navigation just for that URL, without any editor interaction required.

Conditional Logic Inside Any Template

You can also use the is_page_template() conditional inside your regular page.php to apply different markup to pages assigned to a specific template, without creating separate files. This is useful when the layout difference is minor, such as just hiding the sidebar on certain pages:

if ( is_page_template( 'page-full-width.php' ) ) {
    // skip the sidebar
} else {
    get_sidebar();
}

Final Word: WordPress Page Templates and Post Templates

WordPress’s template system gives you precise control over layout without touching shared files. A page template changes how one type of page looks without affecting anything else. A post type template extends that control to custom post types. Slug- and ID-based templates lock a specific layout to a specific page automatically, with no editor interaction needed.

A few things to keep in mind:

  • Always work in a child theme when modifying an existing theme. Template files added to a parent theme get overwritten on the next theme update.
  • The template hierarchy has priority rules. If page-about.php exists in your theme, WordPress uses it before looking at the editor dropdown. Understanding this prevents confusing situations where your assigned template does not take effect.
  • Use is_page_template() for minor layout variations. If the difference between two layouts is just a sidebar or a class name, a conditional inside page.php is cleaner than a separate template file.
  • Not comfortable with PHP? Elementor and full-site editing block themes handle template creation through a visual editor. The PHP file approach gives you the most direct control, but it is not the only path.

Start with the simplest approach that solves the problem. Copy page.php, remove what you do not need, and go from there. Once you understand how the hierarchy works and how WordPress picks template files, the system becomes easy to predict and debug.

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.