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
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.
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.
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.
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.
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.
Ok. Pay the membership fee and i’ll provide the answer. http://wpsites.net/registration/
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.
This works perfectly. Thank you.