WordPress now has Post Templates

Great news for some WordPress developers, WordPress version 4.7 recently came out with an exciting new feature! They now allow post templates similar to the way page templates work.

Activating Post Templates

To activate the new post template feature all you have to do is add your first post template. The one requirement to make them show up in the admin area on the new or edit post screen is that you have to add the following lines to the very top of your new template files:

* Template Name: Your Post Template Name Here
* Template Post Type: CPT, names

That’s all there is to it! Make up a template name for the first parameter and use the Custom Post Type name or names for the second parameter, Template Post Type:.

Lets say you created a custom post type named “movies” and you created a template named movie-posts.php, then your movie-posts.php file would start out like this:

* Template Name: Movie Posts
* Template Post Type: movies

Then go ahead and add your loop and other code to your template file and when you upload it you’ll see a new “template” drop-down appear under the attributes heading in the right column of the edit posts and add new posts screen for that custom post type:



Note that this also works with ACF plugin or Advanced Custom Fields Pro plugin. That should explain it all. I hope this becomes as useful for some of my readers as it already has for me!

Leave a Reply

Your email address will not be published. Required fields are marked *