Load Template File Conditionally

This code loads the template file named featured.php from the child themes root directory.

You can use the code in your child themes functions.php file to load any type of template file conditionally.

In this case it uses the is_singular('page') conditional tag to load the template file named featured.php on all single pages.

Load Single Post Template On Single Pages

If you want to use a single.php post template on single pages you can add a template header to the file like this :

/**
 * Template Name: Single Page Template
 */

This enables you to choose the Single Page Template from the Templates drop down menu in the Page Attributes box on any single page.


Comments

2 responses to “Load Template File Conditionally”

  1. Thanks Brad for all the code snippets you share. Glad to have found your site via Google.

    1. You’re welcome Collins

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.