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.

PHP
/*
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 Name is the label you’ll see in the Template dropdown when you edit a post.
  • Template Post Type is a comma-separated list of post type slugs that can use the template. post and page are built in, and product is 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.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More