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.
Was This Tutorial Helpful?