Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress Page Templates for Custom Post Type

I have a custom post type, "Store Pages" for instance, which is an almost identical duplicate of the default Wordpress "Page" post type.

Like the "page" post type, I would like to create page templates (not post-type templates) and be able to select them from the "Template" drop-down within the "Page attributes" box in the page editor.

I have created several templates, but the drop-down menu does not appear; I am assuming this is because a custom post types does not allow support for this.

Is there a way I can create page templates for a custom post type without using "single-{post-type-name}.php" and having a dozen queries to load up different template files?

I have double checked the comments for the templates are correct as they appear when I create a new page (post type, "Page").

Help would be greatly appreciated.

like image 430
Stefan Dunn Avatar asked Feb 07 '26 03:02

Stefan Dunn


1 Answers

starting 4.7 you can use the new feature described here https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/

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

// … your code here
like image 83
amit Avatar answered Feb 12 '26 06:02

amit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!