Home/ Documentation/ WordPress/ Short guide to naming WordPress templates

Short guide to naming WordPress templates

WordPress decides which template file to use based on what it wants to display. If that file is not present, it looks for the next appropriate file. In the end, if no specialized template files are present in the theme, it uses index.php.

That’s why every WordPress theme needs at least the index.php template.

Here we’ll take a look at what template names to use for the most common use-cases:

One page website 

Just use index.php. Done.

Multi-page website

Use index.php for the home page, and then add additional templates as needed, according to the following guide.

Special template for the home page -> home.php

Site front page (can be latest posts or the page that is set as front page in WordPress admin) -> front-page.php

A template for displaying single post and page -> singular.php

Displaying single post -> single.php

Single page -> page.php

Single custom post type -> single-{post type}.php

Special templates for specific pages or posts

Custom template for single page or post that can be chosen when editing the post / page in WordPress admin -> {any special name}.php, but in Page settings turn on the “Use as post / page template” and fill in the required info.

We can define templates for a particular post or page by using template files like page-{slug}.php, but using Custom templates is the best approach that lets us also reuse such special templates on multiple pages or posts.

Archives

Latest posts (not custom post types, just regular posts) -> home.php or index.php

General archive -> archive.php

Custom post type archive -> archive-{post type}.php

Author archive -> author.php

Category archive -> category.php

Tag archive -> tag.php

General taxonomy archive -> taxonomy.php

Custom taxonomy archive -> taxonomy-{taxonomy}.php

Date archive -> date.php

“Page or post not found” template -> 404.php

Search results -> search.php

This should do for most use-cases. If you need more information about template naming in WordPress check out https://wphierarchy.com/.



Last updated on June 8, 2019 at 5:55 am


Print this article