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.

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

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.