How to Create a Page Template in WordPress (Custom + Single Page)
13 mins read

How to Create a Page Template in WordPress (Custom + Single Page)

 

Table of Contents

Introduction

You are going to create page template in WordPress using your theme files. You will build two template types, based on your needs. The first type is a reusable template you can select. The second type is a page-specific layout that loads automatically. Both methods are useful for real business sites. They help you control layouts without editing every page again. You can use them for landing pages, sales pages, and service pages. You can also use them for custom layouts like full-width pages. If your goal is branding and speed, templates help a lot. This guide stays focused on templates only, not extra design topics.

Choose the right template type for your goal

Before you create files, pick the best approach first. This helps you avoid wrong file names and wrong placement.

Use a selectable template when you want these results:

  • You want one layout for many pages.
  • You want to pick a template inside the editor.
  • You want a clean and reusable site structure.

Use a page-specific template when you want these results:

  • You want one page to look different.
  • You want the layout to load automatically every time.
  • You do not want to select anything in the editor.

Here, you will learn both methods. First, you will start with the reusable approach. That is the common way to how to create a custom page template in WordPress.

Before you start: what you need

Know your theme type first

WordPress templates depend on your theme setup. Many sites still use Classic themes with PHP templates. Some sites use Block themes with Site Editor templates. This guide focuses on PHP template files in themes. That is the most direct and flexible method today. If you use a Block theme, file paths can differ. Still, the core idea of template loading stays similar.

Use a child theme for safe edits

Never edit template files in a parent theme directly. Theme updates can overwrite your changes without warning. A child theme protects your custom work long term. It also keeps your site stable during updates.

Keep these tools ready

You will need basic access to your WordPress files.

  • Hosting File Manager or FTP access
  • A simple code editor like VS Code
  • WordPress admin access to test changes
  • A staging site if your site gets heavy traffic

Create the template file in your child theme

Where to place the new file

Open your child theme folder on the server. You will create a new wordpress page template file there. Most templates sit in the theme root folder. Some developers use a templates folder for organization. For this guide, place it in the root for clarity. This reduces confusion during setup and testing.

How to name the file cleanly

Use a simple file name you can recognize later. Use lowercase and hyphens for cleaner structure. Example names can match your layout purpose, like landing or fullwidth. This file will become your wordpress custom page template.

Add the required template header

Now open the new wordpress page template file you created. You must add a special header comment at the top. This header tells WordPress to list your template in the editor. Without this header, WordPress treats it like a normal file. Keep the header simple and correctly spelled. Use a clear template name that matches your layout goal. This is the core step for a clean wordpress custom page template.

Use this exact header format at the top:

<?php
/*
Template Name: Custom Landing Page
*/

If you want to limit it only for pages, keep it as above. WordPress will still show it under Pages by default. If your setup needs stronger control, you can add a post type line. This is useful when themes add many template options. You can use this version when needed:

<?php
/*
Template Name: Custom Landing Page
Template Post Type: page
*/

Save the file after adding the header block. Your template is now ready for the layout code.

Build the basic template structure

Your template must load the site header and footer. It must also print the page content correctly. To do that, you will use The Loop in the template. The Loop helps WordPress load the right page data. Without it, your page content may not show.

Add this clean starter structure below the header:

<?php
/*
Template Name: Custom Landing Page
*/

get_header();
?>

<main class=”site-main” style=”max-width:1100px;margin:0 auto;padding:24px;”>
<?php
while ( have_posts() ) :
the_post();
the_content();
endwhile;
?>
</main>

<?php get_footer(); ?>

This structure works well for most business pages. It keeps the layout clean and readable for visitors. You can now change the wrapper based on your page goal. For example, you can remove width limits for full-width layouts. You can also add your own sections above or below content. Keep changes small at first, then test on the front end.

Here are safe layout edits you can add later:

  • Add a hero section above the content area.
  • Add a sidebar only if your design needs it.
  • Add a different container style for landing pages.

At this stage, you successfully create page template in WordPress using a proper structure.

Assign the template to a page

Now go to your WordPress dashboard and open Pages. Create a new page or open an existing one. You will now select the template from the editor settings. The exact location depends on your editor view, but the idea stays same.

Follow these steps in the Block Editor:

  • Open the page you want to design.
  • Click the gear icon to open Page settings.
  • Find the Template option in the Page panel.
  • Select your new template name from the dropdown.
  • Click Update or Publish to save the page.

If you use the Classic Editor, look for Page Attributes. You should see a Template dropdown in that box. Select your template and update the page.

After saving, visit the page in a new browser tab. Confirm the layout loads as expected and looks correct. If the content shows, your reusable template setup is complete.

Add a Single Page Template That Loads Automatically

How WordPress decides which template file to load

WordPress follows a simple rule when loading templates. It looks for the most specific file first. If it finds that file, it uses it right away. If it does not find it, WordPress falls back to a more general file. This is why page-specific templates work so well. You do not need to select anything in the editor. The right template loads automatically for that page.

For pages, WordPress usually checks templates in this order:

Ad Banner
  • A page template tied to a specific page slug.
  • A page template tied to a specific page ID.
  • A general page.php template file.
  • A final fallback like singular.php or index.php.

This is the base idea behind add single page template in WordPress. You create a special file that matches one page. WordPress detects it and uses it.

Create a page-specific template file for one page

This method is perfect when only one page needs a unique layout. For example, you may want a different layout for a “Pricing” page. You may also want a clean landing page for ads. With page-specific templates, you can keep the rest of the site unchanged. You only change one page layout through a file.

You can target a page using two options:

  • Slug-based file for a page URL name.
  • ID-based file for a page numeric ID.

Option 1: Slug-based page template file

First, confirm the page slug in WordPress. Open the page editor and check the permalink. The last part of the URL is the slug. If the page URL is /contact-us/, then the slug is contact-us. Now create a new file in your child theme root.

This is the format you will use: page-{slug}.php template WordPress.
Example for contact-us page: page-contact-us.php

This file is not selected from the editor settings. WordPress loads it by matching the slug. This is the simplest way for how to add a single page template in WordPress.

Now add a clean structure inside the file. Use a layout that differs from your normal page.php. Keep it simple and test first.

Example structure for a slug-based file:

<?php
get_header();
?>

<main class=”site-main” style=”max-width:1200px;margin:0 auto;padding:28px;”>
<section style=”padding:18px 0;”>
<h1 style=”margin:0 0 12px;”><?php the_title(); ?></h1>
<p style=”margin:0 0 18px;”>This page uses a custom layout.</p>
</section>

<?php
while ( have_posts() ) :
the_post();
the_content();
endwhile;
?>
</main>

<?php get_footer(); ?>

You can now change spacing, add sections, or remove sidebars. Keep the Loop in place. Without it, content may not show. This approach is clean and easy to manage long term.

Option 2: ID-based page template file

Sometimes your slug may change after updates or SEO edits. In that case, use the page ID method. Go to Pages and hover over your page name. Look at the bottom browser link preview. You will see something like post=123. That number is the page ID. Now create a file like: page-123.php

This is also a single page template approach. It loads automatically for that page ID. It is stable even if you change the slug later. Many developers use this method for permanent layout pages.

Test and confirm the single page template is working

After saving the new file, clear your cache first. Caching can hide your new template file changes. Now open the page in a private window. Check if the layout matches your new file design.

Use these quick checks to confirm it works:

  • The page layout looks different from other pages.
  • Your custom heading or text appears on the page.
  • The content still loads and shows correctly.
  • The header and footer load without errors.

If the page still looks like the default template, check these points:

  • Confirm the file is in the active child theme folder.
  • Confirm the file name matches the exact slug or ID.
  • Confirm the page slug is correct in the permalink.
  • Confirm your site is not serving an old cached version.

Once this works, you have successfully set up a page-specific layout. You now know how to create a reusable template and a single page template.

Troubleshooting WordPress Page Templates: Common Problems and Fixes

Templates work fast when setup is correct. But small mistakes can break the flow. Use these fixes when something looks wrong. These steps help you avoid wasted time during testing.

Issue 1: Template name not visible in the editor

Many users face template name not showing in WordPress page editor. This usually happens due to header issues or file placement. The editor will only show templates with a valid header block.

Fix it with these checks:

  • Confirm the template header is at the file top.
  • Confirm the header has the correct Template Name line.
  • Confirm the file is inside the active theme folder.
  • Confirm the file has a .php extension, not .txt.
  • Confirm you saved the file without hidden characters.

Also confirm you are editing a Page, not a Post. Posts use different template rules. If you made a template for pages only, it will not show for posts.

Issue 2: Wrong theme folder or wrong theme active

This is a very common cause of template confusion. You may add files in one theme folder. But WordPress may be running a different theme. Always confirm the active theme in Appearance settings. Then confirm your file is inside that exact folder. This matters even more when you use a child theme.

Issue 3: The template loads but content is missing

This happens when The Loop is missing or broken. Your template must include a loop to print content. If you see header and footer only, this is the reason.

Fix it fast:

  • Add while have_posts loop in the template.
  • Use the_post and the_content inside the loop.
  • Save and refresh after clearing cache.

Issue 4: Page-specific template not loading automatically

This happens when the file name does not match the target page. For slug templates, one wrong character can fail it. For ID templates, using the wrong ID causes fallback. This also happens when the file sits in the wrong folder.

Fix it with these checks:

  • Confirm the slug exactly matches the page permalink.
  • Confirm the page ID is correct and current.
  • Confirm the file is in the child theme root folder.
  • Confirm you did not add extra spaces in the file name.

If you are using a slug method, remember this format is strict. The best example is page-{slug}.php template WordPress naming. It must match the real slug exactly.

Issue 5: Old layout still shows after changes

Caching can delay changes on many WordPress sites. Hosting cache, plugin cache, and CDN cache can all hold old files. Clear your cache and test in a private window. If you use Cloudflare, purge cache there too. This simple step avoids false debugging.

Conclusion

Now you know two strong ways to control page layouts. You can build a reusable template and assign it easily. You can also create page-specific templates that load by default. This makes your site more flexible and easier to manage. If you want expert help with templates and theme edits, WooHelpDesk can help you. We can fix layout issues, template loading problems, and theme conflicts fast.