How to Create a Page Template in WordPress

Create a Page Template in WordPress

WordPress makes it easy to tweak just about anything you want. But if you want to create one page that stands out from the rest. Creating a custom page template is the best way to do so. You can also use custom page templates if you want a custom header on your homepage or a blog page without sidebars.

This guide covers three ways how you can create a WordPress template page.

Let’s begin.

Top 3 Ways to Create a Basic WordPress Template 

We’ll now look at the top 3 ways to create a custom page template in WordPress.

Method #1: How to make a WordPress template in WordPress using PHP

To create create WordPress template with this method, you’ll need:

  • Text editor
  • FTP client or Hosting Cpanel
  • Access to WordPress’ Admin Dashboard
  • Basic knowledge of PHP and WordPress file structure

Let’s begin…

Step 1: Create Custom Template Page

  • Open up your text editor and copy the following code in it:

<?php /* Template Name: PageWithoutSidebar */ ?>

  • The line of code will tell WordPress that this template is called PageWithoutSidebar when you use it.  You can name the page whatever you want to.
  • Now, go ahead and save this file as PageWithoutSidebar.php. Again, you can go with any name you want to go with. Just make sure to keep the extension as .php.

Step 2: Upload the Template File

Now let’s test this newly created file.

  • Log in to your hosting panel and get the FTP login credentials.
  • Install an FTP client like FileZilla and establish SFTP connection with my server. 
  • Navigate to the /wp-content/themes folder.
  • Now open your active theme folder and upload the PageWithoutSider.php template file you created earlier there. 

Step 3: Select the Template in WordPress

Head over to WordPress Admin Panel > Page > Add New. 

Now, under the page attributes section you should see the new custom page template WordPress listed.

Now set the template to PageWithoutSidebar. Then, click on Publish.

Now open your page and you’ll notice a blank page with a text. That is because you have yet to customize it. This will show you that the page has been successfully created. 

In the next step, you’ll see how you create your own WordPress theme.

Step 4: Adding Content to Your WordPress Page Template

  • Next, we will enter a few lines of code to show content on the page.
  • In order to do this, open your Filezilla FTP client again and edit the PageWithoutSidebar.php file.
  • Now add these lines of code in the file. 
  1. <?php
  2. /* Template Name: CustomLoginPage */
  3. get_header();
  4. ?>
  5. <div id=”primary” class=”content-area”>
  6.    <main id=”main” class=”site-main” role=”main”>
  7.        <?php
  8.       // Start the loop.
  9.        while ( have_posts() ) : the_post(); ?>
  10.       
  11.            <div class=”login-page-intro”>
  12.                <h2>Welcome to Our Site</h2>
  13.                <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>
  14.            </div>
  15.            <div class=”login-form-container”>
  16.                <?php
  17.               // WordPress login form
  18.                wp_login_form(array(
  19.                    ‘redirect’ => home_url(), // Redirect after login
  20.                    ‘label_username’ => __(‘Username’),
  21.                    ‘label_password’ => __(‘Password’),
  22.                    ‘label_remember’ => __(‘Remember Me’),
  23.                    ‘label_log_in’ => __(‘Log In’),
  24.                    ‘remember’ => true
  25.                ));
  26.                ?>
  27.            </div>
  28.        <?php
  29.       // End the loop.
  30.        endwhile;
  31.        ?>
  32.    </main><!– .site-main –>
  33.    <aside id=”custom-sidebar” class=”sidebar-area”>
  34.        <?php if ( is_active_sidebar( ‘custom-sidebar’ ) ) : ?>
  35.            <ul class=”sidebar-menu”>
  36.                <?php dynamic_sidebar( ‘custom-sidebar’ ); ?>
  37.            </ul>
  38.        <?php else : ?>
  39.            <ul class=”sidebar-menu”>
  40.                <li><a href=”#”>Pages</a></li>
  41.                <li><a href=”#”>Account</a></li>
  42.                <li><a href=”#”>Custom Page Template</a></li>
  43.                <li><a href=”#”>Login</a></li>
  44.                <li><a href=”#”>Password Reset</a></li>
  45.                <li><a href=”#”>Pricing</a></li>
  46.                <li><a href=”#”>Register</a></li>
  47.                <li><a href=”#”>Restricted Content</a></li>
  48.            </ul>
  49.        <?php endif; ?>
  50.    </aside>
  51. </div><!– .content-area –>
  52. <?php get_footer(); ?>
  • Now visit the page again and refresh it.
  • You should now see something like this: 

This is a basic-looking page. You can always edit it using custom CSS stylings and HTML to make it according to your liking.

Method #2: How to Make a WordPress Page Template Using Block Editor

This is a simpler and direct method that doesn’t require you to access the FTP client. 

  • In this method, you’ll just be using the WordPress block editor to design a WordPress custom templates. You won’t be needing any extra tools and resources in this one. 
  • Goto a page or post from your Admin Dashboard. In the right sidebar go to the ‘Page’ tab and find the ‘Template’ option.
  • Now, click on the text next to ‘Template’. In the pop-up that appears, click on Create New Template.
  • In the popup, name your template something easy to remember, like “custom WordPress design” and click on ‘Create’
  • Now you will enter the WordPress Template editor, where you can add blocks to customize your theme in your own way. 
  • Click on the ‘+’ button. Then drag and drop blocks like headings, text, images, or other elements you need. 
  • For this example, we’ll use the calendar widget.
  • When you’re satisfied with your design. Click on ‘Save’
  • Now, to use your template, open up the page where you want to use your new template.
  • Click the blue option next to Template, and click on Swap template option.
  • Now choose the template you created.

Method 2.1 (Use Reusable Blocks)

An alternative method you have for creating a WordPress template page is using the Reusable blocks feature in WordPress. In this you can create and save blocks that you can reuse across different pages and posts. 

For example, you can create the blocks you created earlier using the block editor and save them as a reusable block. In this way, you don’t have to recreate the layout of the page every time and can easily add in the block from the saved tab.

Here’s how you can do it.

  • Click inside any block and select all the blocks by tapping CTRL + A or CMD + A on Mac.
  • Click on “Add to Reusable blocks.”
  • Type in a name for the block and click Save. 

Now, whenever you want to use this block, you can simply search, select, and insert it from the block editor. 

Method #3:  How to Create Templates in WordPress Using Elementor Builder

Elementor builder is widely used among front-end developers to create page template WordPress. It provides a simple way to create and manage these templates. 

  • This is how you can create a custom WordPress theme using Elementor. 
  • Install the Elementor plugin and go to the Templates section in the WordPress Dashboard. Then Click Add New.
  • Now choose your template type: Container, Page, or Section. If you have a professional version installed, you will have more options to choose from. For this example, we’ll just go with ‘Page’. 
  • Next, choose a name for this template. 
  • Create on Create Template once you’re done. This will open up the Elementor editor where you can create WordPress theme.

You now have two options. Either create your template from scratch by dragging and dropping the widgets. 

Or you can click on the Folder Icon and use a pre-designed template. For this example, we’ll go with this.

  • So click on the Folder Icon, select a template, and click ‘insert’. Hit the ‘Apply’ button on the pop-up that shows. This will apply the new theme and override any previous settings or changes on the page.
  • To make any changes to the theme, simply drag and drop the widgets such as Heading, images, and buttons onto the page. 
  • When done with your design. Click on the down arrow next to ‘Publish’ and click on ‘Save as Template’ 
  • Type in the name of your template and click on ‘Save’
  • Now, whenever you want to use this template. Simply add a new post or page. And click on Edit with Elementor.

    Then click on the folder icon inside the page. Go to My Templates section, and click on Insert

And that’s all you have to do. And that’s how easy it is to create templates in WordPress using the Elementor Builder. 

Issues and Fixes of Custom WordPress Theme

You may encounter problems when you create a custom WordPress theme. They can vary based on your theme and setup. Below are some of the most common ones faced: 

1. WordPress Template Page Not Showing

If you create a page template in WordPress and it’s not showing up in the editor under ‘Templates’, make sure that: 

  • You saved your custom template file is in the theme’s root or “templates’ folder.
  • The file starts with the following header comment:
  1. <?php
  2. /*
  3. Template Name: Custom Template
  4. */
  5. ?>
  • You have refreshed your WordPress site after uploading your file.

2. Template Changes Not Showing Up on the Page

If you are unable to see your template updates on your page: 

  • Empty browser’s cache (Ctrl + Shift + R) and open your page in incognito.
  • Delete the file. Reupload it. Then re-select the template to the page in the editor.
  • Empty WordPress Cache using a Caching Plugin.

3. Incorrect Template Showing Up

If WordPress is showing a different template when applied.

  • Check if another template file (like page-{slug}.php or page.php} is overriding it.

  • In the debug mode, use get_page_template() to find which template is being loaded.

4. Custom WordPress Template Page Layout Breaking

If conditional tags are not behaving as expected:

  • Make sure they are inside “The Loop” where necessary.
  • Also, make sure the position of the conditional tags. For instance, ‘is_page(‘about’) should go inside the wp_header in the template file.

Final Thoughts

A custom page template is a great way to create specific pages that are different from your WordPress’ theme. They are also reusable, so you can design a page with your desired functionality once and use it on as many pages as you need to. 

You can save time and get professional looking custom WordPress templates with our website development services in USA

Get in touch to get started today!

FAQs

Is there a way to update the WordPress theme without losing my custom code in functions.php and the custom page templates?

It’s best not to insert your custom code inside the parent theme’s file. Add the code into a plugin or place it inside the child theme. 

Can you use a single custom page template for all different kinds of pages in WordPress?

Yes. You can use a single custom page template in all kinds of pages. 

How do you create a custom page template in WordPress with AMP support?

Create a new PHP file in your theme directory and add the necessary AMP HTML structure. Then, insert the AMP tag in your page template and make sure you have the AMP plugin installed and enabled inside WordPress.

What is the most user-friendly way to create a custom page template in a WordPress theme?

The Elementor Page Builder plugin is the most user-friendly way to creare template WordPress. It allows you to create professional-looking pages with the ease of drag and drop functionality. 

Leave a Reply

Your email address will not be published. Required fields are marked *