How to create a new page template in WordPress (even without FTP access)

As a freelance web designer, I often run into projects that require a variety of layouts and unique page templates. As I begin to embrace Gutenberg (see my post on creating Gutenberg blocks) more fully, I'm sure the number of unique templates will begin to decrease. But for now, I still need to create several unique page templates for my custom development projects. In this post, I'll show you how to do that if you have access to FTP. If you're in a pinch and only have access to the WordPress backend, I'll also show you how to create a new page template using a little hack I learned over the years! Let's get started!

Create Page Template Using FTP

  1. Create a new PHP file. Name it something memorable that describes the page template. In this example, I'll create a file called about-us.php.
  2. Copy/Paste the default code from your page.php file. I use the Underscores starter theme and highly recommend it. But it doesn't matter which one you choose.
  3. On the very first line, include the code snippet below. This defines what the page a unique page template.
  4. Save and upload your new PHP file in the root folder of your theme. This is the same folder that contains style.css and other page templates.
  5. Voila! You've created a new page template.
<?php /* Template Name: About Page */ ?>

No FTP Access? No Problem!

If you're in a situation where you can't get access to the FTP but have access to WordPress, you can still create a new page template. To do this, follow these simple steps:

Create a New PHP File

  1. Go to the the theme editor by clicking "Appearance > Theme Editor".
  2. Find the header.php file and click edit.
  3. Insert the code snippet below on the very first line of the header.php file. Be sure to change your theme and file name.
  4. Refresh any page of your website in the browser. This will execute the php touch action and create the the new PHP file in the directory you've specified.
  5. Go back to your Theme Editor and you'll now see the new PHP file in your directory listing.
<?php touch('wp-content/themes/your_theme_directory/about-us.php');?>  

Create the Template File

  1. After you've created the about-us.php file (or whatever you called it), edit the file in your Theme Editor.
  2. Insert the following code snippet on the very first line to create the page template. Be sure to replace About Page with whatever template you are creating.
  3. Save and enjoy your new page template!
<?php /* Template Name: About Page */ ?>

Chris Lam - Freelance Web Design and web development, denton, dallas, ft. worth, dfw