WordPress front page logic is a mess. No — a Mess. :)
It is an old artifact of development, from the time when WP started to break away from purely blogging paradigm. The static front page functionality was added, but in quite an awkward way.
I have stumbled over this innumerable times and finally decided to note down how it works once and for all.
Front page cheatsheet
Default | Static front page | ||
---|---|---|---|
Front page displays | Your latest posts | Front page: Front | Posts page: Posts |
URL | example.com (site URL) | example.com/posts (page URL) | |
Template hierarchy | front-page.php | home.php | |
home.php | - $custom.php
- page-$slug.php
- page-$id.php
- page.php
- singular.php
| ||
index.php | |||
Body classes | - home
- blog
| - home
- page
- page-id-$id
| blog |
Loop and content | posts index | page | posts index |
home_url() | https://example.com | ||
get_post_type_archive_link('post') | https://example.com | https://example.com/posts | |
is_front_page() | true | false | |
is_home() | true | false | true |
is_page() | false | true | false |
get_option( 'show_on_front' ) | 'posts' | 'page' | |
get_option( 'page_on_front' ) | 0 | Front page ID | |
get_option( 'page_for_posts' ) | 0 | Posts page ID |
What is home?
The one especially confusing mismatch to note is that home is all over the place.
home
body class and home_url()
function refer to front page. They mean location in site (Site URL).
home.php
template and is_home
conditional refer to posts index. They mean type of page in site (blog posts).
Front page template
front-page.php
template is great for very custom front pages. Since it has high priority in both cases of template hierarchy — it is hard to override and publicly released themes rarely include it.
Be aware of it for custom builds, it makes things easier for them.
Summary
Default front page behaves as combination of front page and blog posts archive.
Static front page resides at front page location and behaves as a page.
Posts page resides at assigned page’s location, but behaves as a blog posts index (it being a page is mostly ignored).
TL;DR
In a nutshell you use:
- static front page to customize, moving archive from there;
- posts page to change location of posts archive.
janw.oostendorp #
Andrey “Rarst” Savchenko #
singular.php
).