What are the WordPress Template Files? – Explained in Detail

Template files are the files that are responsible to render the page as it is on the WordPress site.

We can define it as The files that exist and the theme and where the developer defines, how your website should be displayed.

Here are the few terms that a WordPress developer needs to understand before starting creating templates files-

Template Files

All WordPress themes are made up of Template files.

These files are the .php files which by using a mixture of HTML, PHP Code, and Template Tags define how a particular page will be rendered.

index.php, archive.php are a few examples of Templates files.

Template tags

They are built-in WordPress Function that we developers use to retrieve and display data like title, category, and content.

Template partials

To simplify the creation of WP themes we use Template Partials.

These are the piece of templates that can include in another template. header.php, sidebar.php, and footer.php is fine example of template partials.

Common WordPress Template files

  • index.php: The main template, if there was no particular template for the page, wordpress would render this page template.
  • style.css: This is the main stylesheet of WordPress theme. It contain theme information and required.
  • rtl.css: stylesheet for the website which uses left to right languages such as arabic, urdu and so on.
  • comments.php: The template partial that we can include to show and allows visitors to leave comments on the page/post type.
  • front-page.php: This page would be applied on the page that we selected as homepage from Admin > Settings > Reading.
  • home.php: Its by defoult front page. If we do not set the custom front page this template will be used.
  • header.php: header of the website, partial template file that we can include in other page templates.
  • footer.php: footer of our wordpress theme.
  • singular.php: WP use these page when single.php or/and page.php not found.
  • single.php: this template is used to render single post, custom post.
  • single-{post-type}.php: it is used to show single post from the custom post type. we replace the {post-type} with the name of post type.
  • archive-{post-type}.php: it is used to show archive of custom post type.
  • page.php: When visitor request any individual built-in pages.
  • page-{slug}.php: we can create specifiec page template for particular page only. we replace the slug part with page slug. we can also use the page id instead of slug.
  • category.php: The category template to render posts by category.
  • tag.php: The tag template to render posts by tag.
  • taxonomy.php: render custom post type posts by custom taxonomies.
  • author.php: It is used when visitor loads author page.
  • date.php: when posts are requested by date this template is used.
  • archive.php: a single template which we can use for category, author, or date. If the particular template for any of these is already present, it will be overidden.
  • search.php: The search result page template. shows the post filtered by specifiec query.
  • image.php: it is used when we are viewing a single image attachment. if it does not exist WordPress would use attachment.php instead.
  • attachment.php: This template is used when viewing a single attachment like PDF, Media file or image.
  • 404.php: This page will be shown when the page does not exist.

How to use template files?

As I mentioned earlier we use Template Tags to retrieve and display information dynamically.

Template tags are not only used to display information from the database but we can include other templates in any templates files.


Once we created header.php we can include this header file in any WordPress template file by using the tag get_header().

Also, if we want to add custom theme files we can use tag get_template_part().

For example, we can create a post loop template and use this tag to add that loop on any page where the post loop is needed.

Leave a Comment