Ever thought of creating custom post templates in WordPress? Apart from Page templates we can also create “Post Templates” which can be used for specific posts to give a different look. This feature is not available is WordPress as default option and can be added by using a simple plugin.
Custom Post Template is a free WordPress plugin that provides a drop-down menu of all available post templates in post edit screen. Select a template for that particular post and
single.php file will be replaced by that template. Pretty simple way do it, but before that you need to create some “Post Templates” by following this method.
Create Custom Post Templates in WordPress
Be careful while creating custom post templates. If anything goes wrong, you will end up breaking theme files. So its recommended to Backup your WordPress theme before trying hands on this tutorial.
Step 2: Create a single Post Template by including this syntax in it.
<?php /* Template Name Posts: Simple */ ?>
While creating a page template we have to define its name in “Template Name:” field. Similarly, for Post Template we need to assign a name by using “Template Name Posts:” field.
In the above example I have named that post template as “Simple” and you can use any other name based on the requirement. Also, this is the name which will be displayed in Drop-Down menu too.
Step 3: After creating the Custom Post template, copy it to your theme directory where
index.php file is located. Please do not use any sub folders or sub directories.
Tip: If you want to create Custom Post Template instantly, then create a copy of
single.php file and rename it. Make all required changes to that renamed file and upload it back to theme folder.
How to use Custom Post Templates in WordPress?
After uploading “Post Templates” to theme folder they will be available to use on individual posts. From the drop-down menu select the “Post Template” you wish to use and hit on publish button.
Voila, a custom post template will be used for article overriding contents in single.php file. Incase if no post templates are available then a message “This theme has no available custom post templates.” will be displayed instead of drop-down menu.
Need some help in setting up a custom template for specific posts? Drop a comment here and we will get back to you.