How to Create a Page Template in WordPress Without FTP Access

This blog is reader-supported. When you make a purchase through links on my site I may make a small commission at no additional cost to you.

One of WordPress’ most powerful features are page templates. Not to be confused with actual posts and pages — also commonly referred to as content types or post types — WordPress page templates are the literal files that are used to render a particular page, post, or post type. At their core, page templates are unique PHP files that reside within a WordPress theme’s file directory. WordPress knows which one to use because it loops through a hierarchal list of possible filename options and renders the page with the first matching template name it finds that exists. When you have FTP access to your WordPress website’s hosting server it’s incredibly easy to upload a new file, but often FTP login credentials aren’t passed out like candy on Halloween to every Joe-the-website-developer who works on your website, so in this article, I’ll show you how to create a page template in WordPress without FTP access.

WordPress Template Hierarchy

[…] template files are modular, reusable files, used to generate the web pages on your WordPress site. Some template files (such as the header and footer template) are used on all of your site’s pages, while others are used only under specific conditions.

-Template Hieraarchy WordPress.org

WordPress decides which template to use by iterating a top-down list of possible template names. Telling WordPress to use a particular template for a particular page, post, or section of your website is as easy as determining which type of page you’re applying a template to, identifying a matching template-name syntax, and creating a file in your active theme’s directory that’s named accordingly.

How WordPress Loops through Page Template Names

By examining the hierarchal WordPress template name flowchart (below), you can see how template names are ordered with the most generic templates on the right-hand side and the more specific and granular templates as you move left. That’s to say you’re entire WordPress website could be powered by a single index.php template, but if any of the templates farther left exist then WordPress will attempt to use those for the matching post/page/post-type as the code it renders before using the template name down the line to the right. You could have a template for single pieces of content (singlular.php), but you could also have another template for single posts, single pages, single custom posts, a singular post, etc. As you can see, there are a lot of ways to leverage WordPress custom page templates for creating unique layouts and designs within your WordPress theme without altering the entire theme of your website.

WordPress Template Hierarchy
WordPress template naming conventions (from granular to generic, moving left to right).

Creating a New WordPress Page Template

  1. Identify the page/post/post type you want to template.
  2. Find an appropriate file name syntax that matches.
  3. Create a new PHP file in your theme’s directory and name it accordingly.

Adding WordPress Page Templates With FTP

When you have FTP access to your WordPress website’s hosting account it’s easy to navigate to the active theme’s directory and create or upload a new PHP file to use as your page template. It’s a matter of logging in and dragging and dropping a new file where it needs to go; WordPress does the rest.

Adding WordPress Page Templates Without FTP

Without FTP access, adding new WordPress page templates is still possible, but it’s slightly less intuitive. WordPress doesn’t have a create new file button in the Appearance->Editor area, however, since WordPress is built on PHP you can take advantage of PHP to create new files when you do not have access to the web host’s file system via FTP.

Creating a New WordPress Page Template on New Website with No Visitors When You’re the Only Administrator Accessing the Site

If you’re the only person using the website then the process of creating a new WordPress page template file can be simple, straightforward, quick, and painless. You don’t have to worry about other people getting in the way, seeing unintended error messages, or gumming up your process. Assuming you’re working with a new website that doesn’t have any visitors and you’re the only one who’s poking around in the administrative area here’s the path of least resistance.

From the WordPress Dashboard, navigate to Appearance->Theme File Editor. Find your theme’s header.php file. Click on it to open the header file for editing and add the following PHP snippet to the very top of the file (as line 1) — remember to update the path to your_theme_directory to point to the name of your active theme’s directory and change the filename.php to the WordPress hierarchy template name you need to create. Execute the PHP command by visiting any page on the front-end (publically accessible) part of your website. Once you’ve run the command, return to the theme’s file editor to verify the new page exists and remove the PHP snippet you added to revert the header.php file back to its original state and prevent yourself from creating new page templates over and over again (that’d be bad and it’d overwrite itself every time you loaded a page on the front-end).

  • Login to WordPress
  • From the Dashboard, navigate to Appearance->Theme File Editor
  • Open header.php for editing
  • Add the PHP snippet as line 1 and update the file to save your changes
  • Visit any public page on your website to run the snippet
  • Return to the Theme File Editor and verify the new page exists
  • Remove the snippet from the header.php file and save the changes
<?php touch('wp-content/themes/your_theme_directory/filename.php');?>

At this point, you can edit the new file.

Creating a New WordPress Page Template on a Live Website where Other People May Be Using at the Same Time as You Are

If you’re working with a live site and don’t know who else is logged in or visiting at the time you’re making changes then it’s worth taking a few precautions and surrounding the (above) PHP snippet with more finely-tuned conditional logic checks before adding it to the page and unleashing it in the wild. It’s better to be safe than sorry, so anything to make it more bulletproof is a good idea.

One approach is to check if the current person viewing the page that executes the code is an administrator. Assuming you’re the only WordPress administrator on the site at the time, checking for administrator privileges prevents a regular person who’s viewing the site from interacting with the PHP code you’re adding, thus, preventing any unexpected errors or experiences that would result in undesirable user experiences for your customers while you’re doing development.

Here’s how that might look:

<?php
if( current_user_can('administrator') ) {
  touch('wp-content/themes/your_theme_directory/filename.php');
}
?>
WordPress Theme File Editor Dashboard
Create a new PHP file using the WordPress Theme File Editor

There are plenty of other WordPress roles and capabilities you can run a logic check for if you need to, but in most cases checking whether the user is an administrator or not is probably enough to get you from point A to point B for the short amount of time you need to muck with the system to accomplish the task at hand — quickly creating a new WordPress page template without using FTP.

Turning the New PHP File into a Working WordPress Template

Turn the new PHP file into a WordPress page template by starting line 1 with the required page template syntax of:

<?php /* Template Name: AN-IDENTIFIABLE-NAME */ ?>

After that, you’re free and clear to add whatever custom template-related-code you want to. Often, it’s easier to get started by copy+pasting code from a similar template into your new template and updating the parts you need, but I’m sure if you’ve come this far that you know what you’re doing from here on out. At this point, you’ve successfully created a new WordPress page template PHP file without using FTP and you’re ready to start custom coding a new WordPress template for your website.

Share this post!

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments