Template: What is it in WordPress?

In the WordPress Theme article, we explained what the WordPress theme consists of. This topic is dedicated to the WordPress template.

As already known, templates together with stylesheets, javascript, and images define how your site looks to the users. WordPress actually has a standard template hierarchy. It means that templates with certain names affect specific website’s areas.

For example, header.php and footer.php files respectively control the header and footer parts of a web page created by a WordPress theme.

What is a WordPress template?

Most WordPress themes have several templates with code generating HTML output for specified website sections. There are some of them:

  • Main – index.php. Displays the main page of a website.
  • Header – header.php. To display the header section.
  • Sidebar – sidebar.php. Generates the sidebar section.
  • Footer – footer.php. To display the footer section.
  • Theme Functions – functions.php. Contains features and functions using in a theme.
  • Single Post – single.php. For displaying the single post page.
  • Comments – comments.php. To display comments and comment form.

Moreover, templates can be included in each other. For instance, single.php can include header, footer, sidebar, and content template. In this case, single.php can have a different header, footer, and sidebar from the header, footer, and sidebar of your site. By the way, WordPress does not deny users to add as many templates as they would like. Some themes also have them for custom loops and sidebars implementation.

Note: WordPress template hierarchy helps to escape the errors. If a theme does not have single.php, then WordPress will roll back to a more general template like index.php.

This article presents a breakdown of which WordPress template files to edit for different pages in a typical WordPress site.