Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WordPress 5 Cookbook

You're reading from   WordPress 5 Cookbook Actionable solutions to common problems when building websites with WordPress

Arrow left icon
Product type Paperback
Published in Mar 2020
Publisher Packt
ISBN-13 9781838986506
Length 660 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Rakhitha Nimesh Ratnayake Rakhitha Nimesh Ratnayake
Author Profile Icon Rakhitha Nimesh Ratnayake
Rakhitha Nimesh Ratnayake
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Setting Up WordPress and Customizing Settings 2. Customizing Theme Design and Layout FREE CHAPTER 3. Using Plugins and Widgets 4. Publishing Site Content with the Gutenberg Editor 5. Managing Users and Permissions 6. Setting up a Blogging and Editorial Workflow 7. WordPress as an Application Framework 8. Improving Usability and Interactivity 9. Building E-Commerce Sites with WooComerce 10. Troubleshooting WordPress 11. Handling Performance and Maintenance 12. Improving Site Security 13. Promoting and Monetizing the Site 14. Other Books You May Enjoy Appendix

Using a custom page as a home page

The default WordPress home page consists of a list of blog posts on the site. The content for the home page is generated within WordPress and is not visible as a post or page in the dashboard. Most sites will require a unique home page that describes the site, rather than a set of blog posts. So, we need the option of changing the default behavior.

The main settings section of WordPress allows us to customize the default behavior and define a custom home page. In this recipe, we are going to look at the process of changing the home page from the default blog post list to a custom page.

Getting ready

We need to have a custom static page as the home page of the site. Follow these steps to create a new page:

  1. Log in to the WordPress Dashboard as an administrator.
  2. Click the Pages menu.
  3. Click the Add New button to create a page.
  4. Add a title of Home and add Home Page as content.
  5. Click the Publish button to create the page.

This will create a new empty page that will be used as the home page of the site.

How to do it...

The process of changing the home page and customizing the blog page is a straightforward task. Follow these steps to configure the home page:

  1. Log in to the WordPress Dashboard as an administrator.
  2. Click the Settings menu.
  1. Click the Reading option. You will get a screen similar to the following called Reading Settings:

We'll be using the Your homepage displays setting for this process. The Your latest posts option will be selected by default to show the blog posts on the home page.

  1. Select the A static page (select below) option.
  2. Select the page we created in the Getting ready section as the home page.
  3. Select another page for the Posts page option and use it as the blog posts page.
  4. Click the Save Changes button.

Now, visit the home page of the site by clicking on the site title. You will see the new page we created in the Getting ready section with the content as Home Page. Also, you can go to the Pages list and click on the page we used for the Posts page setting to view the list of blog posts.

We have changed the home page successfully and used a custom page. Now, you can add home page content that's specific to your site by modifying the custom page we created in the Getting ready section.

How it works...

The setting for displaying the front page is stored in the wp_options table in the database with a key called show_on_front. The default value is posts. Therefore, the blog post list will be shown on the front page. Once we select and save the A static page (select below) option, the value of show_on_front will change to page.

Next, the Homepage and Posts page options will be saved in the wp_options database table with the page_on_front and page_for_posts keys. Once pages have been selected for these settings, the page_on_front and page_for_posts keys will hold the respective page IDs. The default value will be 0 for these settings.

Once the user request is sent for the front page, WordPress will use page_on_front to load the respective page as the home page. Also, when the blog post page is clicked, WordPress will check if the requested page is defined in the page_for_posts setting. Once a match has been found, it will display the list of blog posts.

There's more...

Once we select a page to be used for the posts page, WordPress will override the content of that page with the blog post list. The content of the page won't be visible anywhere on the frontend of the site.

Also, we may choose the same page for both the Homepage and Posts page settings by mistake. In such a case, a warning message will be displayed. If we continue using the same page without considering the warning, WordPress will load the blog posts list as the front page.

You have been reading a chapter from
WordPress 5 Cookbook
Published in: Mar 2020
Publisher: Packt
ISBN-13: 9781838986506
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime