By default, WordPress does not allow you to create custom post templates for individual posts. It only allows you to do this for the “page” post type. However, Hybrid Core has a built-in post templates system that works similar to page templates in WordPress.
When I say “post” template, I’m referring to posts of any post type. So, you can have custom templates for regular ol’ blog posts as well as a custom “movie” post type, for example.
Adding theme support for post templates
If you’re using a theme from here, you shouldn’t need to do this step. Most themes already support this feature out of the box.
If you’re building a custom parent theme off the Hybrid Core framework, you’ll need to add the following line of code to your theme setup function.
add_theme_support( 'hybrid-core-template-hierarchy' );
Creating a custom post template
As I mentioned earlier, post templates work nearly the same as page templates, so if you’re familiar with creating custom page templates, this should be pretty easy.
Suppose you wanted to create a post template called “Super” for your posts. You’d need to create a new PHP file in your child theme and name it something like
post-template-super.php. At the very top of this file, add the following code block.
<?php /** * Post Template: Super */ ?>
The big thing you have to do is use the name of the post type here. Since you’re creating a post template, you’d use the term “Post.”
Let’s take a look at another example. Suppose you had a custom post type named “Movie” and wanted to create a custom template that’d you’d select for certain movies. Let’s call this template “Adventure” just for the sake of example. You’d create a new template named
movie-template-adventure.php and place the following code block at the top of the file.
<?php /** * Movie Template: Adventure */ ?>
As far as what code goes in your template files, that’s entirely up to you. It is a custom template after all.
How to use post templates
For any public post type, a “Template” meta box will appear on the edit post screen in the admin as shown in the following screenshot. It will allow you to select one of your templates for your post.
Just save your post and your post will use your custom post template on the front end of the site.