Have you tried Flywheel? Learn moreJoin the best designers and creative agencies in the world. Learn more

×
How to set a static front page in WordPress

How to set a static front page in WordPress

WordPress’ origins as a blogging software are never more evident than in two places: the default content types WordPress comes with set up (Posts and Pages), and that by default,  your blog posts will be displayed on your homepage. However, many of the sites you’ll build for clients call for a different, specific homepage.  In this short tutorial I’ll show the three basic ways to achieve this.

Method one: Using the Settings

Fortunately (for us and our clients), WordPress has been updated over the years to accommodate static homepages quite easily. After installing WordPress and your theme, login to the WordPress Dashboard. Navigate to Settings and then to Reading.

static1

 

The very first option on the Reading page is to set the front page display to either your latest posts (by default) or to designate a static front page. You’ll notice that if you select a static page,  you also have the option of selecting another page to display your posts.  Most of the time, when I’m building a WordPress site,  I’ll create a page titled “Home,” and a page titled “Blog,” for this very purpose, and set them here.

static2

Method two: Create a front-page.php

There is another way to set a static front page.  WordPress recognizes certain PHP files for certain tasks, and if those files aren’t found, it will default to more common files like page.php and index.php. This is known as the WordPress Hierarchy, and is a useful and important concept to understand when building a custom theme or simply adjusting elements in someone else’s theme.

In the WordPress Hierarchy, if a file called front-page.php exists in your theme,  WordPress will automatically always display it as the static front page. Using the same logic, if home.php exists, WordPress will always use that file to display your posts. If your design calls for very specific mark-up on both of those pages, these special template files help make sure that the right markup is displayed at the right time. If you need to be a little more flexible, I suggest creating files like template-featured.php.

Method three: Create template files

By creating template files, you’ll be able to choose on a page by page basis which template to use. This allows you to reuse a template for multiple pages (besides just the front page), which will save your work and keep your code easy to maintain.

To make a template file, simply create a new .php file in your text editor, and at the very top of the page, type in a comment like this:

<?php

/*

Template Name: Featured

*/

;?>

When you go to edit a page, you’ll notice a new select element in the Page Attributes metabox, right below the publish metabox. All you have to do to use the mark-up in the new template is select it, then, to set that page as the static front page, just make sure it is set in Settings.

Whichever method you choose, these are not exclusive options. You can use them together to quickly and simply make the changes you need to make to the page most of your visitors will see first. To review, here are the ways we can set a static front page:

  1. We can select one using the Settings
  2. We can create a front-page.php
  3. Or we can create as many template-[name].php as we like, choose templates on a page by page basis, and then use Settings to make sure the static front page is the page we want to display, with the template and content we want to display.

1 Comment

Join the discussion

Share this article:
Get more great content in your inbox

More articles

Get content like this sent directly to your inbox!

Install WordPress locally free