最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can I override a CPT template on a per post basis with Gutenberg block editor?

programmeradmin2浏览0评论

I have a CPT defined in code called event, and there is a template file for the markup (single-event.php).

I am wondering if it is possible to override a post within the Event CPT with the Gutenberg block editor, instead of using the php template every-time, is this possible?

I would ideally like the template file to apply to all my CPT posts, except one or two of them, which will require much different display.

EDIT: I guess in a more generic sense I am looking for optional template functionality for a CPT. Ability to use the provided template, or ignore it and utilize the block editor with Gutenberg.

I have a CPT defined in code called event, and there is a template file for the markup (single-event.php).

I am wondering if it is possible to override a post within the Event CPT with the Gutenberg block editor, instead of using the php template every-time, is this possible?

I would ideally like the template file to apply to all my CPT posts, except one or two of them, which will require much different display.

EDIT: I guess in a more generic sense I am looking for optional template functionality for a CPT. Ability to use the provided template, or ignore it and utilize the block editor with Gutenberg.

Share Improve this question edited Jun 3, 2019 at 22:21 PressWord asked Jun 3, 2019 at 21:55 PressWordPressWord 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Since 4.7 Custom Post Types have supported custom templates, just like Pages. So you could copy your theme's generic page template to a new template file, and add this to the top.

<?php
/*
Template Name: Block editor template
Template Post Type: my-post-type
*/

That will let you switch the template for your my-post-type post to a template that looks and works just like a normal page.

发布评论

评论列表(0)

  1. 暂无评论