WordPress lets you create multiple page templates so that different pages can have different layouts — a full-width landing page, a sidebar-less contact page, or a custom archive — all within the same theme.
Problem: How do you create a custom page template in WordPress so editors can assign it to individual pages from the admin?
Solution: Create a PHP file in your theme folder with a Template Name: comment in the file header — WordPress discovers it automatically and adds it to the page template dropdown in the editor.
A page template is just a PHP file in your theme folder with a special file header comment. Create, for example, page-full-width.php:
<?php
/**
* Template Name: Full Width
* Template Post Type: page
*/
get_header();
?>
<main id="main" class="site-main full-width">
<?php
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content', 'page' );
}
?>
</main>
<?php
get_footer();
After saving the file, the template appears in the Page Attributes → Template dropdown on the Edit Page screen.
The Template Post Type header line (added in WordPress 4.7) controls which post types the template is available for. You can list multiple types:
/**
* Template Name: Sidebar Left
* Template Post Type: page, post, portfolio
*/
To check which template is active on the current page:
if ( is_page_template( 'page-full-width.php' ) ) {
// do something
}
NOTE: Page template files can be placed inside subfolders — WordPress scans the entire theme directory recursively. This makes it easy to organise templates into a page-templates/ folder without affecting functionality.