There are many many ways yous can alter the look of a specific folio on your WordPress site. Y'all can modify the content inside the WordPress content editor. Yous tin can change the CSS rules that touch on the site. Or create a new file in your WordPress theme'due south template hierarchy to correspond to the specific page. Or you can use a theme page template designed specifically for that page. The final 1 is what we're talking near here. In this tutorial we'll cover both how to create a WordPress custom page template, and why you might want to do that. Nosotros'll offset with the why.

When you say "WordPress Theme Custom Folio Template", what do you mean?

Screenshot of WordPress Page Attributes Template dropdown in WordPress 5.6

There's a huge terminology problem with this topic. As I hinted at to a higher place, there are a lot of things with the vague notion of "page" and "template" in the WordPress world that aren't what we're talking nearly here. The showtime thing I *don't* mean when maxim "WordPress custom page template" is "a WordPress theme." (Many people new to WordPress say "templates" when they mean "a WordPress theme.")

Then what do I mean by "custom folio template"? I mean what is shown at right. For case, yous're editing the Page content type in WordPress (although, equally nosotros'll run across later, it tin at present include other WordPress content types). And while editing your page, you detect the "Page Attributes" box, And inside that, you might (dependent on if your theme already has these templates) see this "Template" dropdown. This selection box is illustrated on the right (it's also on the right side of your "folio editing" screen). If you see this dropdown, it's because your theme provides some of these "custom page templates." They're actually files in your currently agile theme's folder (or its parent), and have a unmarried distinguishing feature we'll come to later. Just this selectable dropdown of named page templates is what we're talking well-nigh here today.

How Does This Fit Into the Template Hierarchy?

I've written before, and I'll probable do so again, nigh how the template — there's that word again — hierarchy is really the fundamental concept you lot need to understand to build or modify a WordPress theme. (Here'due south our quick intro to it.) Nearly everything else is a item you lot can work out once you've understood the basic dynamic of the template hierarchy. The specific thing we're significant today, though, sits outside of the template hierarchy. This "selected template" essentially replaces the whole selection process of the template hierarchy.

If a Custom Folio Template was selected in the dropdown we showed above, that "template" file will be used. Full end, no exception.

To restate that, if a custom page template is selected, that "template" file will be used. Full terminate, no exception. If not, then the WordPress template hierarchy will look for a somewhat different way that someone might accept tried to way a specific folio — with a page-123.php or page-custom-template-utilizer.php file. (The difference between the Custom template, and ane with this folio-$id or page-$slug structure is really only in interaction and interface.) If neither of those is found, WordPress will fall back to folio.php, if it exists, and if non we'd end upwardly at the ultimate fallback, alphabetize.php.

If yous're wondering why y'all'd utilize this method as opposed to the numeric or slug one — in either case you lot're creating a custom file in your theme, after all — the reason is that using custom templates gives you more flexibility and independence between your theme and your site's database and content. For that reason, I'd recommend it in merely virtually every situation when yous're unsure which to go with. With the numeric or slug-based page-*.php construction, you're forced to brand your theme know about the specific fashion your WordPress database data is right now. (Then if yous reuse the theme on a different WordPress site, for example, that file is useless.)

How Do I Make a WordPress Custom Folio Template?

OK, so we know that custom page templates volition supervene upon the WordPress template hierarchy. And that we'll make utilise of them on bodily pages of our WordPress site by selecting them from a "Template" dropdown card on the right-bar of the relevant slice of content. So it's time to get to the process for creating a WordPress custom folio template.

What you'll exercise is, add to your theme (and information technology actually should be a child theme unless there's a very strong constraint making that impossible for you) a file with a name similar my-template.php or really-cool-awesome.php. It doesn't really thing, as long as you don't actually utilise a name that'south part of the template hierarchy, you're gilded. (Which ways: do not use a proper noun similar folio-whatever.php. As we touched on to a higher place, WordPress'south template hierarchy thinks it owns a file named with that pattern.)

One time you've got the file (cool-folio-template.php, of any y'all prefer), you should start it like this:

          <?php /* Template Proper name: Name To Announced In The Dropdown */ ?> This is my custom template.                  

And you're basically done. As you can probably approximate, the proper name that will appear in the "Template" drib down is what I cleverly called "Name To Appear In The Dropdown." Just like your theme'southward manner.css file, or a plugin'southward main file, WordPress uses the information inside this lawmaking annotate to provide it with context to work.

Then the content of our pages will, in this instance be the very basic HTML text "This is my custom template". As yous might guess, here is where you're much more likely to put the HTML contents you desire to announced on the page. So your <h1> tags, <p> tags, and mayhap (if you're fancy 🤪) some PHP to practise custom behavior you lot want to evidence off.

Why Your WordPress Custom Page Template Doesn't Evidence Upwardly

I've (more than one time) had the feel that my new WordPress folio template doesn't show up. By far the most common crusade is that I've typoed (or misremembed) what the file header comment should look like. It needs to be labelled with the precise right title. And so Template Name: Narrow Folio is perfect, but WordPress will never locate something that's instead got a header of Template: Custom.

At that place are a few other things to check on. Other reasons you might find that your custom folio template isn't showing upwards:

  • You put the file in the incorrect place (it needs to be in your current running theme, or its parent)
  • You gave your template a file that starts with page-. Because of a characteristic of WordPress themes, custom page templates that start with folio- are instead treated as page of the template hierarchy.
  • Your theme is missing i of its ii crave files, and then isn't working. (WordPress themes *must* take an alphabetize.php file and a fashion.css.)
  • There was an result with this back in the days of WordPress 4.9 (some years ago now)

Page Templates for non-"Page" WordPress Custom Mail service Types

For a large part of WordPress's history, these "custom folio templates" were only for the "Page" content blazon. (WordPress simply has two content types, "Posts" and "Pages" past default.) But in WordPress four.7, the feature was added that y'all could apply these folio templates with new content types (often called "custom post types").

To do this, yous add together another line to your "file header." So it'd look a little like this:

          <?php /* Template Proper noun: Narrower Template Template Post Blazon: post, page, issue */ // Page HTML and PHP goes hither...        

As you lot can probable guess, this new Template Mail service Type: header prefaces the "code-level" proper noun for the (custom) post types. Yous'll note that in the higher up instance, we list the page content type that WordPress ships with, likewise every bit the post one. In addition, we're supporting a third "custom post type" chosen event.

A Nifty Reason To Use Custom Page Templates

Now if you've done this before, yous'll notice that the folio to a higher place will have no styling, and wait very very fiddling similar the rest of your WordPress site (unless y'all have the simplest theme imaginable). That'south because our file has one simple thing in it, and lacks functionality very common in all other theme pages. It has no get_header(), get_footer(), or The Loop, calls that all your other theme files likely exercise.

Sometimes yous want a page that's not much like the rest of your site, just still a part of your WordPress management experience. These custom templates are perfect for that.

But information technology illustrates one of the slap-up powers of custom templates like these likewise: sometimes you want a page that's not much like the residuum of your site, but still a office of your WordPress management experience. These custom templates are perfect for that. While y'all meet them used also for archives pages, or (less commonly) contact pages, this ability is often overlooked.

And Finally, Some Practical Advice About Page Templates

When you're looking to brand page that looks just like your other pages (but a little different) I'd really start by copying an existing file from your theme, probably folio.php. This is simply because nearly of us find it easier to change something than to build from scratch. The code example gives your folio template that "blank white page" sense, where you lot're probably looking to add or remove some specific details from your existing folio.php template. Removing the sidebar or the footer, for example, are very common reasons that people brand a "custom page template" in WordPress.

As nosotros've covered, if you duplicate your theme'south page.php file to kickoff making your custom page template, you'll need to make sure you add the "custom page template header" we've got above. Again, those are the "magic" page that makes these templates just work. Now, go make awesome pages!

Prototype credit: Infrogmation