How to Enable Page Attributes and Template Selection for Custom Post Types
Content
If you've created a custom post type (CPT) with the Custom Post Type UI plugin and found that the Page Attributes meta box, particularly the Template dropdown, is missing, you're not alone. This is a common point of confusion that stems from how WordPress core handles templates for custom post types.
Why This Happens
Unlike standard Pages, custom post types do not automatically inherit the ability to select a page template from a dropdown. The Template dropdown is a feature native to the built-in 'page' post type. When you enable the 'Page Attributes' option in Custom Post Type UI, it primarily controls the 'Parent' page dropdown and the 'Order' field, not necessarily the template selector.
The Core WordPress Solution
Starting with WordPress 4.7, the platform introduced a more robust method for assigning templates to any post type. The solution involves creating template files in your theme that are specifically named for your custom post type.
Here is the most common method to enable template selection:
- Create a Template File in Your Theme: Add a new file to your active (preferably child) theme's directory. The filename must follow this structure to be recognized by WordPress:
// For a single post view of a CPT with the slug 'my_cpt' single-my_cpt.php // For an archive view of a CPT with the slug 'my_cpt' archive-my_cpt.php - Add a Template Header Comment (Optional): To make a template appear in the dropdown menu within the WordPress editor, you can add a special comment at the top of any PHP template file. This method works for any post type, including your custom ones.
The<?php /** * Template Name: My Custom Layout * Template Post Type: my_cpt, post, page */ ?>Template Post Type:line is key. List the slugs of the post types you want this template to be available for, separated by commas. In this example, the template becomes available for the custom post type 'my_cpt', as well as standard posts and pages.
Important Considerations
- Child Theme Recommended: Always make these changes in a child theme. This prevents your modifications from being overwritten when the parent theme is updated.
- Theme Support Varies: The ability to use the
Template Post Typeheader depends on your theme's structure. Most modern themes support it, but if you encounter issues, you may need to consult your theme's documentation. - This is a WordPress Feature: It's important to understand that this functionality is provided by WordPress core. The Custom Post Type UI plugin provides the interface to register the post type, but the template system is handled entirely by WordPress.
By following these steps, you can successfully create and assign custom templates to the post types you manage with Custom Post Type UI, giving you greater control over the layout and design of your content.
Related Support Threads Support
-
Page Attributes in the CPT madehttps://wordpress.org/support/topic/page-attributes-in-the-cpt-made/
-
Create capability for CPTshttps://wordpress.org/support/topic/create-capability-for-cpts/
-
Custom Post Type Mediahttps://wordpress.org/support/topic/custom-post-type-media/
-
See CPT posts on admin’s users menuhttps://wordpress.org/support/topic/see-cpt-posts-on-admins-users-menu/
-
Woocommerce Custom Post Typehttps://wordpress.org/support/topic/woocommerce-custom-post-type-2/
-
How register existing CPT in pluginhttps://wordpress.org/support/topic/how-register-existing-cpt-in-plugin/
-
Use a post type as taxonomyhttps://wordpress.org/support/topic/use-a-post-type-as-taxonomy/
-
Newsletter Helphttps://wordpress.org/support/topic/newsletter-help/
-
transition_post_status hookhttps://wordpress.org/support/topic/transition_post_status-hook/
-
create/publish/edit cpt meber types posts using elemenotr prohttps://wordpress.org/support/topic/create-publish-edit-cpt-meber-types-posts-using-elemenotr-pro/
-
Sticky Postshttps://wordpress.org/support/topic/sticky-posts-43/
-
list all posts of all (post types) in a single admin interfacehttps://wordpress.org/support/topic/list-all-posts-of-all-post-types-in-a-single-admin-interface/
-
Avada Element Post Slider with CPThttps://wordpress.org/support/topic/avada-element-post-slider-with-cpt/
-
Woocommerce post type visibile in CPT UIhttps://wordpress.org/support/topic/woocommerce-post-type-visibile-in-cpt-ui/
-
Store User information in CPThttps://wordpress.org/support/topic/store-user-information-in-cpt/
-
I read the tutorial. Need sample how to add mime type. (In my case, JFIF (jpg).)https://wordpress.org/support/topic/i-read-the-tutorial-need-sample-how-to-add-mime-type-in-my-case-jfif-jpg/
-
Using the Descriptionhttps://wordpress.org/support/topic/using-the-description/
-
Need help with CPT UI Pluginhttps://wordpress.org/support/topic/need-help-with-cpt-ui-plugin/
-
get_post_types() => post types of the plugin onlyhttps://wordpress.org/support/topic/get_post_types-post-types-of-the-plugin-only/
-
CPT post as a user profile.https://wordpress.org/support/topic/cpt-post-as-a-user-profile/
-
Example moving post to CPTUI using switcher pluginhttps://wordpress.org/support/topic/example-moving-post-to-cptui-using-switcher-plugin/
-
custom post type for beginnershttps://wordpress.org/support/topic/custom-post-type-for-beginners/
-
Do any related post plugins work with this plugin?https://wordpress.org/support/topic/do-any-related-post-plugins-work-with-this-plugin/
-
Possible / best way to determine if a CPT is registered by this plugin?https://wordpress.org/support/topic/possible-best-way-to-determine-if-a-cpt-is-registered-by-this-plugin/
-
Can This Plugin Integrate with Events Pluginhttps://wordpress.org/support/topic/can-this-plugin-integrate-with-events-plugin/