WordPress: Easy to remember template hierarchy

Aide memoir for the WordPress template hiearchy…

Default for everything – archive pages, single posts and single pages (as well as all other content types):

1st: index.php

Select template by page for specific archive displays, like category and taxonomy archives or templates for different page layouts:

1st: template_{$custom-post-type}.php or template_{NOSIDEBAR}.php
2nd: index.php

For all pages that do not exist:

1st: 404.php
2nd: index.php

The user submits a search:

1st: search.php
2nd: index.php

Latest blog posts:

1st: front-page.php
2nd: home.php
3rd: index.php

For whichever page is assigned as the front page:

1st: front-page.php
2nd: home.php
3rd: index.php

For a single post page:

1st: single-{$post-type}-{$slug}.php
2nd: single-{$post-type}.php
3rd: single.php
4th: singular.php (fallback for single.php AND page.php)
3rd: index.php

For a single page:

1st: custom_template.php
2nd: page-{$slug}.php
3rd: page-{$id}.php
4th: page.php
5th: singular.php (fallback for single.php AND page.php)
6th: index.php

For a category page:

1st: category-{$slug}.php
2nd: category-{$id}.php
3rd: category.php
4th: archive.php
5th: index.php

for a tag page:

1st: tag-{$slug}.php
2nd: tag-{$id}.php
3rd: tag.php
4th: archive.php
5th: index.php

For custom taxonomy pages:

1st: taxonomy-{$taxonomy}-{$term}.php
2nd: taxonomy-{$taxonomy}.php
3rd: taxonomy.php
4th: archive.php
5th: index.php

For Custom Post Types:

1st: archive-{post_type}.php
2nd: archive.php
3rd: index.php

For an author info page:

1st: author-{$author-nicename}.php
2nd: author-{$author-id}.php
3rd: author.php
4th: archive.php
5th: index.php

For a date page archive:

1st: date.php
2nd: archive.php
3rd: index.php

For an attachment page:

1st: {$MIME-type}.php (one of: image.php, video.php, pdf.php, application.php, etc.)
2nd: attachment.php
3rd: single-attachment-{$slug}.php
4th: single-attachment.php
5th: single.php
6th: singular.php
7th: index.php

For embeds:
1st: embed-{$post-type}-{$post_format}.php
2nd: embed-{$post-type}.php
3rd: embed.php
4th: wp-includes/theme-compat/embed.php


Leave a Reply