How To Make A WordPress Post (Not Page!) Your Home Page

Making a WordPress Page your home page is easily done by using the Theme Customizer to select a static home page.

But what about a post? How do you select a post as your home page?

With a simple bit of coding that takes advantage of the WordPress chain of execution.

Featured image of a post as a home page
If you want to use a post as your home page then you’ll need to resort to coding.

The Great Discontent is a great looking magazine that features fascinating “interviews on beginnings, creativity, and risk”.

One of the design features that has always intrigued me about the site is that it uses the latest post as its home page. No messing around with the normal ‘gateway’, it’s straight into the most recent (long form) story.

WordPress doesn’t have this functionality baked in. It’s very easy, via the theme customizer or the Reading Settings (Settings > Reading)  to choose a static page as your home page, or a post list, but you cannot select a post as your home page.

So, if you want to make a post your home you’ll need to resort to a bit of hacking but fortunately the code snippet is small. Add it either as a plugin (as provided) or simply take the function and add it to your functions.php.

{code type=php}
function pfp_pre_get_posts ( $query ) {

// only interested in home page and the main query
if ( !$query->is_home() || !$query->is_main_query() ) return;

// default args – most recent post
$args = ‘posts_per_page=1&order=DESC&orderby=date&ignore_sticky_posts=true’;

// check for sticky posts
$sticky = get_option( ‘sticky_posts’ );

// have sticky posts so use them
if ( $sticky != ” ) {
$args = ‘p=’ . $sticky[0];
}

// clear the current query
$query->init();

// parse in the new arguments
$query->parse_query( $args );

}

add_action( ‘pre_get_posts’ , ‘pfp_pre_get_posts’ );
{/code}

All the code does is hook into the pre_get_posts action to reset the query retrieving the posts. It only does this if the page being output is the home page and this is the main query – this should leave your menus and widgets in tact.

The function will first try to use any ‘sticky’ posts; if there are none then it will simply grab the most recent post.

The simplicity of the code is down to WordPress’s chain of events. The query gets altered before WordPress determines which template to use to display the page, so by changing the query to bring back just a single post it automatically selects the single post template for building the output.

Of course, there are other ways to achieve the same outcome. You could use a static page and either embed a shortcode to pull in the content of a post or create a specific template to get the content; or you could make use of the WordPress template hierarchy and create a home.php file for your theme that pulled the appropriate content.

But neither seem as elegantly simple as the plugin.