Can I assign a template to a custom post type?

Can I assign a template file to a custom post type?

I have created a custom post type called items, and I would like to assign templates to the items like you can do with pages.

8

From WordPress version 4.7 you can now assign custom page templates to other post types along with page.

To achieve this in addition to the Template Name file header, the post types supported by a template can be specified using Template Post Type: as following.

<?php
/*
Template Name: Full-width page layout
Template Post Type: post, page, product
*/

You can get more information about it on the following pages.

https://wptavern.com/wordpress-4-7-brings-custom-page-template-functionality-to-all-post-types
https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/

Leave a Comment