This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Every 1 second delay costs up to 20% conversions. Learn how to fix it [Free • Mar 10–11]. Save My Spot→

How to Create a Custom Page Template in a WordPress Theme

Updated on May 22, 2025

13 Min Read

Key Takeaways

  • A WordPress page template lets individual pages have unique layouts without affecting the rest of your site.
  • You can create custom page templates using PHP code, the built-in block editor, or a page builder plugin like Elementor.
  • The template header comment at the top of the PHP file is what registers the template in WordPress.
  • Always use a child theme when adding custom templates to avoid losing changes on theme updates.

One of WordPress’s most important selling points is its endless customization potential. As a WordPress user, you want more control over your site’s design and functionality.

WordPress is great at this. Its flexibility allows basically anyone to change anything about their site. Speaking of which, page templates in WordPress allow you to customize the design of your site, just the way you like.

Things like adding a header to your homepage or adding/removing sidebars from a blog page can all be done with page templates.

Basically, if you want a specific page to look different from the rest of your site, you’ll have to use page templates. A lot of WordPress websites use custom page layouts for their landing pages and sales pages.

So…if you wanna achieve the same for your website, this guide is for you. In this blog, we’ll take a look at various methods to create a custom page in WordPress.

Let’s get started.

Why Use a Custom Page Template in WordPress?

Having a single cohesive theme adds great value to the website’s design and functionality. However, some websites prefer having different designs for different pages.

Unfortunately, several WordPress themes restrict users from altering layouts and functionality for a different page in the hierarchy.

A WordPress custom page template allows users to integrate custom requirements such as a right/left sidebar on a particular page, additional call-to-action functionality, or a unique header for a particular landing page.

A custom WordPress page template could be used for a number of purposes. For example, to:

  • Show recent posts of each category
  • Embed Google Maps or any script
  • Show a list of all authors
  • Show recently uploaded images
  • To create a custom-designed portfolio page
  • etc …

A template file named page.php handles the appearance of all pages and posts created on a WordPress website. Creating or editing a custom page template in WordPress requires basic knowledge of HTML, CSS, and PHP, and this foundation becomes even more important when working with advanced setups like headless WordPress where front-end and back-end are decoupled.

See How Performance Issues are Diagnosed in Real Time

On Mar 10–11, performance specialists walk through real WordPress sites and explain each optimization decision step by step.

Free 2-day online Bootcamp

WordPress Page Template Hierarchy

WordPress determines how a page is displayed based on your theme’s template files. By default, it uses page.php for all pages unless a different template is specified.

When a page request is made, WordPress follows a structured hierarchy to select the most appropriate template. The order of selection is:

  1. Custom Page Template – If a specific template is assigned to the page in the editor, WordPress uses it.
  2. page-{slug}.php – If no custom template is set, WordPress looks for a template that matches the page’s slug (e.g., page-about.php).
  3. page-{id}.php – If a slug-based template is not available, WordPress checks for a template with the page’s numeric ID (e.g., page-10.php).
  4. page.php – If no ID-specific template exists, WordPress falls back to the default page.php file in the theme.
  5. singular.php – If page.php is missing, WordPress will use singular.php, which is a generic template for individual pages and posts.
  6. index.php – If no other templates are available, WordPress defaults to index.php, the core template used for rendering content.

This hierarchy ensures WordPress selects the most specific template available for each page while maintaining a fallback system when specific files are not provided.

Accelerate WordPress Load Times by 70% With Cloudways Cloudflare Addon!

Improve your website performance & score higher on Core Web Vitals with Cloudflare’s Edge Page Caching for WordPress!

How to Create a Basic Custom Page Template (3 Methods)

Now for the good stuff. We’re now going to take a look at four different methods to create a custom page template in WordPress.

Method#1: How to Create a Custom Page Template in WordPress Using PHP Code (Manual Method)

For this method, you’ll need:

Let’s get started…

Step 1: Add the Template Code

  • Simply open any text editor and paste the following code into it.

<?php /* Template Name: PageWithoutSidebar */ ?>
  • The line of code will tell WordPress that this is a template file called PageWithoutSidebar—when we use it. You can use any name you want. Now save this file as PageWithoutSidebar.php. Again you can use any other name for the file. But don’t forget to keep the extension as .php.

Step 2: Upload the Template File

Step 3: Select the Template in WordPress

  • Go to WordPress Admin Panel > Pages > Add New. Next, in the page attributes section, you should see the new custom page template listed.

  • Open the newly created page. As there are no design elements in the template yet, a blank page like the image below will show up.

Step 4: Adding Content to Your Custom Template

  • It is now time to add a few lines of code to display content on the page.
  • To do this, edit the PageWithoutSidebar.php file. I’ll use FileZilla to add the code below to my file now.
<?php
/* Template Name: CustomLoginPage */
get_header();
?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post(); ?>
        
            <div class="login-page-intro">
                <h2>Welcome to Our Site</h2>
                <p>Please log in to access your account. If you don’t have an account, you can register to become a part of our community.</p>
            </div>

            <div class="login-form-container">
                <?php
                // WordPress login form
                wp_login_form(array(
                    'redirect' => home_url(), // Redirect after login
                    'label_username' => __('Username'),
                    'label_password' => __('Password'),
                    'label_remember' => __('Remember Me'),
                    'label_log_in' => __('Log In'),
                    'remember' => true
                ));
                ?>
            </div>

        <?php
        // End the loop.
        endwhile;
        ?>
    </main><!-- .site-main -->

    <aside id="custom-sidebar" class="sidebar-area">
        <?php if ( is_active_sidebar( 'custom-sidebar' ) ) : ?>
            <ul class="sidebar-menu">
                <?php dynamic_sidebar( 'custom-sidebar' ); ?>
            </ul>
        <?php else : ?>
            <ul class="sidebar-menu">
                <li><a href="#">Pages</a></li>
                <li><a href="#">Account</a></li>
                <li><a href="#">Custom Page Template</a></li>
                <li><a href="#">Login</a></li>
                <li><a href="#">Password Reset</a></li>
                <li><a href="#">Pricing</a></li>
                <li><a href="#">Register</a></li>
                <li><a href="#">Restricted Content</a></li>
            </ul>
        <?php endif; ?>
    </aside>

</div><!-- .content-area -->

<?php get_footer(); ?>
  • Paste this code into PageWithoutSidebar.php just below this line of code and save it: <?php /* Template Name: PageWithoutSidebar */ ?>
  • Your complete PageWithoutSidebar.php file will look like below.
<?php /* Template Name: PageWithoutSidebar */ ?>

<?php
/* Template Name: CustomLoginPage */
get_header();
?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post(); ?>
        
            <div class="login-page-intro">
                <h2>Welcome to Our Site</h2>
                <p>Please log in to access your account. If you don’t have an account, you can register to become a part of our community.</p>
            </div>

            <div class="login-form-container">
                <?php
                // WordPress login form
                wp_login_form(array(
                    'redirect' => home_url(), // Redirect after login
                    'label_username' => __('Username'),
                    'label_password' => __('Password'),
                    'label_remember' => __('Remember Me'),
                    'label_log_in' => __('Log In'),
                    'remember' => true
                ));
                ?>
            </div>

        <?php
        // End the loop.
        endwhile;
        ?>
    </main><!-- .site-main -->

    <aside id="custom-sidebar" class="sidebar-area">
        <?php if ( is_active_sidebar( 'custom-sidebar' ) ) : ?>
            <ul class="sidebar-menu">
                <?php dynamic_sidebar( 'custom-sidebar' ); ?>
            </ul>
        <?php else : ?>
            <ul class="sidebar-menu">
                <li><a href="#">Pages</a></li>
                <li><a href="#">Account</a></li>
                <li><a href="#">Custom Page Template</a></li>
                <li><a href="#">Login</a></li>
                <li><a href="#">Password Reset</a></li>
                <li><a href="#">Pricing</a></li>
                <li><a href="#">Register</a></li>
                <li><a href="#">Restricted Content</a></li>
            </ul>
        <?php endif; ?>
    </aside>

</div><!-- .content-area -->

<?php get_footer(); ?>

  • Go back to your page and refresh it. Now you should see a new custom page template like this:

So, from a blank page to a page with some content, you, my friend, have just created a custom page template. Now, I know it doesn’t look the best right now. But trust me, when you customize it to your liking, your page will look great.

Method#2. How to Create a Custom Page Using the Block Editor

This method is a simpler, more streamlined alternative to creating a custom template with SFTP access. Here, you’ll use WordPress’s built-in block editor to design a custom page template without needing any external tools. This is ideal if you want a quick, reusable layout for multiple pages.

  • Start by opening any page or post in the editor. In the right-hand menu, go to the ‘Page’ tab and look for the ‘Template’ option

  • Click on the text next to ‘Template.’ In the popup that appears, select the ‘Create new template’ option

  • In the popup, give your template a name that’s easy to recognize, like “Custom page template,” and then click on “Create

  • Now, you’ll enter the template editor, where you can add content blocks by clicking the blue ‘+’ button. Drag and drop blocks like headings, text, images, or other elements you need

  • Let’s add the calendar widget as an example

  • When you’re satisfied with the design, click the ‘Save’

  • To use your template, open the page where you want to apply it. Click next to ‘Template’ and then the Swap template option

  • Then, choose the template you just created

Alternative: Use Reusable Blocks

Another way to create a custom page template is by using reusable blocks in WordPress. This allows you to save and reuse a set of blocks across different pages or posts, making the process more efficient.

For example, we can use the blocks we used earlier to create the page with the block editor and save them as a reusable block. This way, instead of manually recreating the same layout every time, we can quickly insert the saved block.

Here’s how to do it:

  1. Click inside any block and press CTRL + A (or CMD + A on Mac) to select all the blocks.
  2. Click on “Add to Reusable Blocks.”
    Selecting Add To Reusable Block
  3. Give the reusable block a name and click Save.
    Enter Name For Reusable Block

Now, whenever we need to apply the same layout to a new page, we can simply search for the reusable block in the block editor and insert it.

Reusable Block Now Available

Method#3. How to Create a Custom Page Using a Plugin (Elemantor)

Creating custom page templates in WordPress can significantly enhance your site’s functionality and appearance.Elemantor, with its theme builder functionality, provides an efficient way to create and manage these custom templates.

Here’s how you can create a custom page template using Elemantor:

  • Now, Elementor will ask you to choose a template type: Container, Page, Section. If you’re using the pro version, you’ll get more options to choose from. I’ll just choose page for this example. Next, I’ll also have to name my template.

  • Click on Create Template when done. This opens the Elementor editor where you can start building your template.
  • To use a pre-designed template, click the Folder icon.

  • If starting from scratch, drag and drop the elements you need onto the page. I’ll just use a pre-designed template for the sake of simplicity. For this, pick any template and click on “Insert”.

  • Hit Apply when a popup appears. This will override the design, layout, and other settings of the Page you’re working on.

  • Customize the template by dragging and dropping widgets such as headings, images, buttons, or forms onto the page. I simply made some tweaks by adding a couple of images to my template.

  • Once you’re happy with the design, click the down arrow next to the Publish button and select Save as Template.

  • Name your template and click Save. Now your template is saved and you can use it wherever you like.

  • To use the template you created just now, go to Pages > Add New and click Edit with Elementor.

  • Click the Folder icon, find your saved template under My Templates, and click Insert.

  • Once inserted, here’s how my template will look like when I preview it.

  • That is it. This is how easy it is to build custom page templates in WordPress with a website builder plugin like Elementor.

Common Problems & Fixes When Using Custom Page Templates

Below are some of the most common problems with custom page templates, but depending on your theme and setup, you may run into others.

1. Custom Page Template Not Showing in WordPress

If your custom page template doesn’t appear in the page editor under “Template,” ensure that:

  • The file is saved in your theme’s root or “templates” folder.
  • The file starts with the correct header comment, like this:
<?php
/*
Template Name: Custom Template
*/
?>

2. Changes to Custom Template Not Reflecting on the Page

If updates to your custom template aren’t showing:

  • Clear your browser cache or use an incognito window.
  • Delete and reassign the template to the page in the editor.
  • Ensure WordPress isn’t serving a cached version from a caching plugin.

3. Incorrect Template Being Applied

If WordPress is loading a different template than expected:

    • Check if another template file (like page-{slug}.php or page.php) is overriding it.
    • Use get_page_template() in a debug mode to see which template is being loaded.

4. Custom Page Template Breaking the Layout

If your custom template causes layout issues:

5. Custom Template Not Working with Conditional Tags

If conditional tags don’t behave as expected:

  • Make sure you’re using them within “The Loop” where necessary.
  • Double-check the conditions; for example, is_page(‘about’) should be inside the wp_head hook or template file.

Fastest Managed WordPress Hosting at Just $11/Month*

Experience blazing fast server speeds with Cloudways LAMP + NGINX hybrid stack. Improve your Core Web Vitals today.

Conclusion

Custom WordPress page templates give you precise control over individual page layouts without changing how the rest of your site looks. Create them once and reuse them across any number of pages.

Three methods cover the full range of technical comfort levels:

Method Best For Requires Code?
PHP File via FTP Developers who need full layout control Yes
Block Editor Non-technical users who want a quick reusable layout No
Elementor Users who want visual drag-and-drop design No

For any method, the underlying principle is the same: define a layout structure, save it as a reusable template, and assign it to specific pages. Once you have this workflow in place, creating distinctive pages for landing pages, sales pages, portfolios, or custom login screens takes minutes rather than hours.

If you think I missed something, feel free to let me know in the comments.

Q. What is a WordPress Page Template?

A. A WordPress page template is a PHP file in your theme that controls the layout and structure of a specific page. It overrides the default page.php file and lets individual pages have unique designs and functionality.

Q. How Do I Create a Custom Page Template in WordPress?

A. Create a PHP file with a template header comment at the top (/* Template Name: YourName */), upload it to your active theme folder via FTP, then assign it to a page in the Page Attributes panel in the WordPress editor.

Q. Do I Need to Know PHP to Create a WordPress Page Template?

A. No. The block editor method and Elementor both let you create custom page templates without writing any PHP. The PHP method offers more control but requires basic familiarity with PHP file structure and FTP access.

Q. Why is My Custom Page Template Not Showing in WordPress?

A. The most common causes are the file being saved in the wrong location, the template header comment being missing or incorrectly formatted, or the admin panel not being refreshed after upload. Check all three before troubleshooting further.

Q. Can I Use a Custom Page Template on Multiple Pages?

A. Yes. A custom page template can be assigned to as many pages as needed. Create the layout once and apply it wherever appropriate from the Page Attributes dropdown.

Q. What is the WordPress Page Template Hierarchy?

A. WordPress checks for templates in this order: a custom template assigned in the editor, page-{slug}.php, page-{id}.php, page.php, singular.php, and finally index.php. The most specific match wins.

Q. Should I Add Custom Page Templates to My Parent Theme or Child Theme?

A. Always add custom templates to a child theme. Adding them to the parent theme means they will be deleted the next time the theme receives an update.

Q. How Do I Apply a Page Template in WordPress?

A. Open the page in the WordPress editor, find the Template option in the Page Attributes panel on the right side, and select your custom template from the dropdown. Publish or update the page to apply the change.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour