The WordPress Template Hierarchy

The WordPress hierarchy refers to the structure and organization of files and templates that WordPress uses to generate and display different types of content on a website. Understanding this hierarchy is crucial for developers and designers who want to customize the appearance and functionality of a WordPress site. Here’s a breakdown of the key components of the WordPress hierarchy:

1. Index.php

  • Purpose: The main template file. It is the fallback template that WordPress uses if no other template files are found.
  • Usage: Typically, it serves as the base template for the entire site.

2. Home.php

  • Purpose: Used for the blog posts index page (the main page that displays the latest posts).
  • Usage: If home.php is not present, WordPress will use index.php.

3. Front-page.php

  • Purpose: Used to display the front page of the site.
  • Usage: This can be set in the WordPress admin under Settings > Reading. If front-page.php is not present, WordPress will use home.php or index.php.

4. Single.php

  • Purpose: Used for displaying individual posts.
  • Usage: If single.php is not present, WordPress will use index.php.

5. Single-{post-type}.php

  • Purpose: Used for displaying individual posts of a custom post type.
  • Usage: For example, single-product.php would be used for displaying individual products if you have a custom post type named “product”.

6. Page.php

  • Purpose: Used for displaying individual pages.
  • Usage: If page.php is not present, WordPress will use singular.php or index.php.

7. Page-{slug}.php

  • Purpose: Used for displaying a specific page based on its slug.
  • Usage: For example, page-about.php would be used for the page with the slug “about”.

8. Page-{id}.php

  • Purpose: Used for displaying a specific page based on its ID.
  • Usage: For example, page-4.php would be used for the page with the ID of 4.

9. Archive.php

  • Purpose: Used for displaying archives of posts, such as categories, tags, and date-based archives.
  • Usage: If archive.php is not present, WordPress will use index.php.

10. Archive-{post-type}.php

  • Purpose: Used for displaying archives of custom post types.
  • Usage: For example, archive-product.php would be used for displaying archives of the “product” custom post type.

11. Category.php

  • Purpose: Used for displaying posts by category.
  • Usage: If category.php is not present, WordPress will use archive.php or index.php.

12. Tag.php

  • Purpose: Used for displaying posts by tag.
  • Usage: If tag.php is not present, WordPress will use archive.php or index.php.

13. Author.php

  • Purpose: Used for displaying posts by author.
  • Usage: If author.php is not present, WordPress will use archive.php or index.php.

14. Date.php

  • Purpose: Used for displaying posts by date.
  • Usage: If date.php is not present, WordPress will use archive.php or index.php.

15. Search.php

  • Purpose: Used for displaying search results.
  • Usage: If search.php is not present, WordPress will use index.php.

16. 404.php

  • Purpose: Used for displaying the 404 error page (page not found).
  • Usage: If 404.php is not present, WordPress will use index.php.

17. Comments.php

  • Purpose: Used for displaying and managing comments on posts and pages.
  • Usage: This file is included within other templates (like single.php or page.php) to display the comment section.

18. Attachment.php

  • Purpose: Used for displaying individual attachments (media files).
  • Usage: If attachment.php is not present, WordPress will use single.php or index.php.

19. Image.php

  • Purpose: Used for displaying individual image attachments.
  • Usage: If image.php is not present, WordPress will use attachment.phpsingle.php, or index.php.

20. Custom Templates

  • Purpose: Custom templates can be created for specific pages or post types.
  • Usage: These are defined in the WordPress admin under Page Attributes when editing a page.

Summary

The WordPress hierarchy allows for a high degree of customization by providing multiple template files that can be used to control the appearance of different types of content. By understanding and leveraging this hierarchy, developers can create highly tailored and responsive WordPress themes.

bleeper

the newsBleeper is a news outlet for the llatest news in social media, technology and programming.

Related Posts

Full PHP course

Laracast has been so kind to share this video on laracast.com, a full 11 hour PHP course for beginners PHP is essential for working with wordpress or dynamic websites. PHP…

Continue reading
What does the functions.php do?

In WordPress, the functions.php file is a crucial part of your theme. It acts as a central hub for adding custom functionality to your theme without having to create a…

Continue reading

Leave a Reply

Your email address will not be published. Required fields are marked *

Don't miss these stories...

Your hidden anatomy – The Human biofield

  • By bleeper
  • July 18, 2025
  • 49 views
Your hidden anatomy – The Human biofield

Marijuana (cannabis)

  • By bleeper
  • February 2, 2025
  • 24 views
Marijuana (cannabis)

Dr Bryan Ardis nicotine exposure

  • By bleeper
  • January 31, 2025
  • 29 views
Dr Bryan Ardis nicotine exposure

Oregano (Origanum vulgare)

  • By bleeper
  • January 31, 2025
  • 31 views
Oregano (Origanum vulgare)

the Open Quantum Safe

  • By bleeper
  • October 22, 2024
  • 30 views
the Open Quantum Safe

Free Energy, otherwise known as Overunity is 100% real – Ashton Forbes

  • By bleeper
  • October 20, 2024
  • 47 views
Free Energy, otherwise known as Overunity is 100% real – Ashton Forbes