• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2762

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Premium Access
  • Log in

Using Different Custom Single Post Templates

WordPress includes a handy filter named single_template which you can use in a custom function.

Here’s a few examples:

Note: Please copy ALL the code from the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++

Single Post Template for Posts In Different Categories

This code enables you to display a custom single post template for all single posts in category-1

Download Folder

Installation Steps #

There’s only 2 steps :

Step 1 – Copy & paste the PHP code from the functions.php file to the end of your child themes functions file.

You will then need to modify the conditional tag in the code to target the category you want to customize. This line in the code will need modifying to match the category slug for your category.

if ( in_category( 'category-one' ) ) {

Example : If your category is named News with a slug news, the code will look like this :

if ( in_category( 'news' ) ) {

Step 2 – Upload the file named single-category-one.php to your child theme folder. You can then remove or add code to this file to modify the default single post template for your specific category.

Single Post Templates for Custom Post Types

This code enables you to display a custom single post template for all single pages using the custom post type portfolio.

Register for full access

Related Tutorials

  • Load Custom Single Post Template For Specific Category & Child Categories
  • Custom Single Template For Genesis
  • 5 Ways To Use a Single Post Template for Custom Post Types
  • Use Any Template Anywhere in Your WordPress Theme

Reader Interactions

Comments

  1. R B says

    September 17, 2019 at 9:12 pm

    Hi Brad and thanks for the code. Unfortunately, it’s not working with the Breakthrough Pro theme. Have you tried it with that theme by any chance? If so, any idea why it’s not working please? Thanks.

    Log in to Reply
    • Brad Dalton says

      September 18, 2019 at 12:45 am

      Hi Richard. I tested my code with Breakthrough Pro right now and it works. Happy to retest in your live site if you want to send me login details. Make sure the category slug and path to the custom single template match whats in the code.

      Log in to Reply
  2. Brad Dalton says

    October 15, 2014 at 5:39 am

    If you’re only currently using one custom post type, you can either use the WordPress Template Hierarchy to name the template for your CPT. Example single-cpt.php

    Or you can use template_include

    Or one of the code snippets in the post above.

    Log in to Reply
  3. Scott Buehler says

    October 15, 2014 at 3:30 am

    Brad, how would I go about adding multiple single template CPTs to this function?

    if ($post->post_type == ‘portfolio’) {

    If I tried if ($post->post_type == ‘portfolio’, ‘secondcpt’) {
    it would fail because it isn’t in an array.

    Hopefully this is quick enough to answer. Know you are busy.

    Log in to Reply
    • Brad Dalton says

      October 15, 2014 at 4:20 am

      Ok. Pay the membership fee and i’ll provide the answer. http://wpsites.net/registration/

      Log in to Reply
    • Brad Dalton says

      October 15, 2014 at 5:19 am

      Here’s the solution Scott

      Simply change the name of the custom post types in the array to match yours. Example: ‘portfolio’, ‘views’

      And change the file name for the single CPT template to your own as well.

      Here’s more on the use of the template_include function.

      Log in to Reply
      • Scott Buehler says

        October 15, 2014 at 5:54 am

        This works perfectly. Thank you.

        Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting