How To Assign Template For Custom Post Type

Quick Summary
- Add a Template Post Type line after Template Name at the top of the template file, listing which post type slugs can use it.
- For a custom post type, add the slug used in register_post_type() to the list, then choose the template in that entry's Template dropdown.
- Without the Template Post Type line, WordPress offers the template only for pages.
WordPress only offers page templates for pages unless you say otherwise. The Template Post Type header lets a single template file appear in the template selector for posts, pages, WooCommerce products or any custom post type.
Create a PHP file in your theme or child theme folder, for example template-full-width.php, and put this comment block at the very top, right after the opening <?php tag. The template’s own markup goes below it.
/*
Template Name: Full-width page layout
Template Post Type: post, page, product
*/How it works
WordPress reads these header lines when it looks for templates:
Template Nameis the label you’ll see in the Template dropdown when you edit a post.Template Post Typeis a comma-separated list of post type slugs that can use the template.postandpageare built in, andproductis the product post type that WooCommerce registers.
To use the template with your own custom post type, add its slug to the list: the same name you passed to register_post_type() when you created the custom post type. Then open an entry of that type, choose “Full-width page layout” as its template and update it. WordPress now loads your file for that entry instead of the default single template.
If you leave out the Template Post Type line, the template is only available for pages.
Related articles
- a single-{post_type}.php template: one layout for every entry of a type, without choosing per entry
- how I organize template files in a custom theme: where custom templates fit in a larger theme

