How-To Guides and Blog

💡 How to create a Custom Single Post Template

NBH Support
NBH Support
No Comments

I would like to start by saying how much I love my current WordPress theme. It’s the first premium theme that I bought and at the time it fulfilled all my needs.

However, over time I started to hate dislike the single page template because of the sidebar. So, today I decided to change the single post template to make it distraction-free by centering the content, removing the sidebar and adding spacing from both sides.

Before we get to the technical stuff, I highly recommend creating a Child theme first prior to any changes.

Are you ready for the coding? Okay, here we go:

Step 1. Open your theme folder and copy single.php  file, then rename it to something else like new-template.php THAT’S IT!

How to create a Custom Single Post Template, 💡 How to create a Custom Single Post Template, New Blog Hosting, New Blog Hosting

That’s basically the fastest way to create a new template for single posts. Forget about plugins. or hiring a WordPress developer. It’s that easy to create a new post template. Now modifying, that’s a whole new thing.

Create New Single Post Template

If you’d like to create a new page template from scratch, you can do so by creating a new template-name.php file and add the following code:

https://gist.github.com/stefanpejcic/f40a09a009801982c303699499de7a77

That’s it, you now have a new template to choose from when creating a post/page:

How to create a Custom Single Post Template, 💡 How to create a Custom Single Post Template, New Blog Hosting, New Blog Hosting

Category based Single Post Template

If you want to have different templates for posts under different categories, you can do so by adding the following inside the functions.php file:

https://gist.github.com/stefanpejcic/e2c4b0d97bf0d65c41991027002d430b

This code will detect the category for the current post and show different single post template based on that.

Author based Single Post Template

If you want to have different templates for different authors, you can do so by using the same principles and adding this code to your functions.php file:

https://gist.github.com/stefanpejcic/f76bb9ecbdf263ddbb832ac474b2448b

For more information about Post Templates check this WordPress.org documentation.

Leave a Comment