Wordpress info

How to Create a Custom WordPress Page Template

Table of Contents

Custom page templates let you break free from your theme’s default layout. Want a full-width landing page, a custom portfolio grid, or a unique contact layout? A page template gives you total control without touching the global theme design.

What Is a Page Template?

A page template is a PHP file in your theme that WordPress recognizes as a selectable layout. When you create a page and choose the template from the dropdown, WordPress uses that file instead of page.php. Templates are perfect for landing pages, custom archive layouts, and specialty pages.

Step 1: Create the Template File

In your (child) theme folder, create a new PHP file. Add this header comment at the very top:

<?php
/* Template Name: My Custom Layout */
?>

Save it as my-custom-layout.php. The “Template Name” appears in the WordPress page editor dropdown.

Step 2: Add the Template Structure

A basic template includes the header, footer, and your custom content:

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

Step 3: Add Custom HTML/PHP

Between get_header() and get_footer(), add your layout — custom sections, loops, forms, or static HTML. You can query specific posts, create grids, or embed anything PHP can generate.

Step 4: Assign the Template

Edit any page in wp-admin, find the Template dropdown (in the Page tab or sidebar), select “My Custom Layout”, and update. Visit the page — your custom layout renders.

Best Practices

  • Always use a child theme so updates don’t overwrite your template
  • Keep templates modular — reuse header/footer functions
  • Escape output with esc_html() and esc_attr() for security
  • Test on staging before deploying to live

Frequently Asked Questions

Do I need to know PHP? Basic PHP helps, but you can build simple templates with mostly HTML. The WordPress loop is the main concept to understand.

Can I use page builders with templates? Yes — many page builders let you design a template visually and export it. Or use a builder on a page assigned to your custom template.

Why doesn’t my template appear in the dropdown? The file must be in the active theme folder with a valid “Template Name” comment at the very top. Clear any caching if it still doesn’t show.

Conclusion

Custom page templates unlock layout freedom in WordPress. Start with a simple template, master the WordPress loop, and gradually build complex layouts. Always work in a child theme to protect your work from updates.