8.3 C
London
Thursday, April 18, 2024

Beginner’s Guide to WordPress Template Hierarchy

Date:

Related stories

WHO hosts the first forum on traditional medicine

The World Health Organization will convene its first summit...

Despite profit-taking, the price of oil still records a weekly rise

As the dollar rose and oil speculators took profits...

Kenya bans churches after allegations of killing worshipers who were starved

According to a government document made public on Friday,...

We will explain the WordPress template hierarchy for beginners in this article. This cheat sheet comes in handy when customizing a template or developing a custom WordPress theme.

Pro Tip: Want to make your own landing pages without having to change your WordPress theme? Try SeedProd, the top-rated drag-and-drop WordPress page builder.

Why Should You Study WordPress Template Hierarchy?

Templates, stylesheets, javascript, and images are all components of modern WordPress themes. These files work together to determine how your site appears to users.

The template hierarchy in WordPress is standard. This means that templates with specific filenames have an impact on specific areas of your website. It also informs you of the template name to use for a specific item.

Most modern WordPress themes include templates for displaying category, date, archives, single posts, custom pages, and other information. You can add more templates as a user by creating a child theme.

Having said that, let’s take a look at how the WordPress template hierarchy works in the background.

WordPress Template Hierarchy Visualization (Cheat Sheet)

For template names, WordPress employs an easy-to-understand and meaningful pattern. The next visual cheat sheet explains which template files are being used to display various pages on a WordPress site.

Here’s an analysis that the WordPress template files to edit for each page of a typical WordPress site.

Which template files does the home page use?

WordPress displays your blog posts on the home page of your website by default. You can also configure it to use a custom home page (also known as the front page) in the WordPress admin area by going to the Settings » Reading page.

  1. front-page.php – If you use a static front page, WordPress will look for this template file first and use it to display the front page.
  2. home.php – If you are using a static front page and your theme does not include a front-page.php template, WordPress will look for a home.php template. It’s also used to show the default blog posts on the homepage.
  3. index.php – If front-page.php or home.php do not exist, WordPress will display the homepage using the index.php template. This is WordPress’s default fallback template for displaying any page.
Read Also  Six Best WordPress Ad Management Plugins and Solutions

Which template files are used by each individual post?

To display a single post, WordPress looks for these files.

  1. single-post-type-slug.php – Use this template to change the appearance of a single post in any post type. If the post type is ‘review’ and also the post slug is acme-phone, WordPress will look for single-review-acme-phone.php.
  2. single-post-type.php – WordPress will then check to see if there is a template for displaying this particular post type. If the post type is review, for example, WordPress will look for single-review.php.
  3. single.php – WordPress will revert to single.php.
  4. singular.php – This template adds a new fallback option for displaying a single item from any post type.
  5. index.php – Finally, as previously stated, WordPress eventually falls back to index.php.

Which template files does a single page use?

Pages are one of the default post types in WordPress. They enable you to create static pages on your website rather than posts.

  1. Custom Page Template – This is the page template that has been assigned to the page. Learn to make a WordPress custom page template.
  2. page-slug.php – If the page slug is contact-us, WordPress will look for page-contact-us.php to use.
  3. page-id.php – If the page ID is 17, WordPress will search for a template file called page-17.php.
  4. page.php – This is the template that will be used to display all static pages.
  5. singular.php – This template serves as a fallback for all single post type items.
  6. index.php – The fallback template by default.

Which template files do category archives use?

These files are used by WordPress to display category-related pages.

  1. category-slug.php – This template is used to display a specific category’s archive page. If the category slug is reviews, WordPress will look for the category-reviews.php template.
  2. category-id.php – WordPress then searches for a template that contains the category ID. If the category ID is 17, for example, WordPress will look for category-17.php.
  3. category.php – This is the WordPress default template for displaying all category archive pages.
  4. archive.php – This is WordPress’s default template for displaying archive pages.
  5. index.php – This is the default fallback template.
Read Also  How to Add a Customer Reviews Page in WordPress

Tag archives rely on which template files?

These files are used by WordPress to display tag archive pages.

  1. tag-slug.php – WordPress will look for tag-fruits.php if the tag’s slug is fruits.
  2. tag-id.php – If the ID of the tag is 17, WordPress will search for the tag-17.php template.
  3. tag.php – The tag archive’s default template.
  4. archive.php – The archive page’s default template.
  5. index.php – This is the default fallback template.

Custom taxonomy archives use which template files?

WordPress’s default taxonomies are categories and tags. Users can also make their own custom taxonomies. The following is how WordPress searches for templates to display custom taxonomy pages.

  1. taxonomy-taxonomy-term.php – If you have a custom taxonomy called genre and a term called ‘thriller,’ WordPress will look for taxonomy-genre-thriller.php.
  2. taxonomy-taxonomy.php – WordPress would look for taxonomy-genre.php if the taxonomy was genre.
  3. taxonomy.php – The standard template for displaying any custom taxonomy archives.
  4. archive.php – WordPress’s default fallback for all archive pages.
  5. index.php – WordPress’s default fallback template.

Custom post types use which template files?

Here’s how WordPress looks for templates to display archives of custom post types.

  1. archive-post type.php – If you have a review post type, WordPress will look for archive-review.php.
  2. archive.php – WordPress’s default template for displaying all archive pages.
  3. index.php – WordPress’s default fallback template.

To display author archives, which template files are used?

WordPress automatically creates archive pages for each author on your WordPress site. This is how the author archive template appears.

  1. author-nicename.php – WordPress will look for author-matt.php if the author’s nice name is Matt.
  2. author-id.php – WordPress will look for author-6.php if the author’s user ID is 6.
  3. author.php – The WordPress default template for displaying author archive pages.
  4. archive.php – WordPress’s default template for displaying all archive pages.
  5. index.php – WordPress’s default fallback template.

To display date-based archives, which template files are used?

WordPress also displays your posts on archive pages for months and years based on the date they were published. This is how the templates for these pages appear.

  1. date.php – The default date-based archive template.
  2. archive.php – The default template in WordPress for displaying author archive pages.
  3. index.php – WordPress’s default fallback template.
Read Also  How to Track Outbound Links in WordPress

Which template files are used to render search results?

  1. search.php – The default page in WordPress for displaying search results.
  2. searchform.php – The WordPress template for displaying a search form.
  3. index.php – WordPress’s default fallback template.

To display 404 error pages, which template files are used?

When WordPress is unable to locate the requested content, the 404 error page is displayed. See our guide on how to improve your 404-page template for more information.

  1. 404.php – The WordPress default template for displaying the 404 error page.
  2. index.php – WordPress’s default fallback template.

To display attachment pages, which template files are used?

  1. MIME type.php – Mime type is an abbreviation for file type. Image.php, video.php, and application.php are a few examples.
  2. attachment.php – The template used by default to display attachment pages.
  3. single-attachment.php – This file is used to display a single attachment.
  4. single.php – The default template for displaying items from a single post type.
  5. index.php – WordPress’s default fallback template.

To display embeds, which template files are used?

Since WordPress 4.5, you can use templates to render a WordPress-embedded post.

  1. embed-post-type-post format.php – WordPress will first search for a post type and post format template. If you have a video review, for example, WordPress will look for embed-review-video.php.
  2. If the post type is review, WordPress will look for embed-review.php.
  3. embed.php – The fallback file for all embeds.

We hope this tutorial was useful in teaching you about the WordPress template hierarchy. You might also be interested in our list of the best drag-and-drop WordPress page builders.

If you liked this post, please find and follow us on InstagramTwitter and Facebook.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome & exclusive content in your inbox, every week.

We don’t spam! Read our privacy policy for more info.

Your Blog Master
Your Blog Masterhttp://yourblogmaster.com
Your Blog Master is more than just a blog; it’s a community of like-minded individuals passionate about technology. Join us in discussions, share your insights, and learn from others.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

We don’t spam! Read our privacy policy for more info.

Latest stories