New Post Type Templates in WordPress 4.7 themes

As themes developers, we’ve always been able to create specific page templates. Now since WordPress 4.7, we can also define templates for specific post types. The code is very simple and is more of an addition to the existing page template declaration:

 Template Name: 3-columns layout
 Template Post Type: post, page, product
 // … your code here

That’s basically it, with the second line you declare to which post types this template can be applied to. And the template box in the admin will show-up accordingly. This snippet would go at the top of your template’s php file, after the opening php tag.

Very practical to get an even better control over templates for you theme.

Leave a Reply

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