admin管理员组文章数量:1410716
I've created a plugin from which I want to load the template for my custom post type. I've used this guide to load the template from plugin Click Here!
The templates are loaded perfectly in the page
post type even though I've already specified the custom post type name in the page template header.
Template Post Type: custom-post-type
I can create a template in the theme folder and it perfectly works with custom post type.
I've created a plugin from which I want to load the template for my custom post type. I've used this guide to load the template from plugin Click Here!
The templates are loaded perfectly in the page
post type even though I've already specified the custom post type name in the page template header.
Template Post Type: custom-post-type
I can create a template in the theme folder and it perfectly works with custom post type.
Share Improve this question edited Nov 13, 2019 at 7:41 bueltge 17.1k7 gold badges62 silver badges97 bronze badges asked Nov 13, 2019 at 6:09 Arman KhanArman Khan 112 bronze badges1 Answer
Reset to default 1The templates in your plugin don't show up in your CPT because the templates are loaded from your theme (or child theme).
You'll need to either
- Place the template in the root theme / child theme folder or
- Create a placeholder template file that "calls" the original
In the second case (which I've had to do a few times), I use something like this for the template in the theme / child theme:
<?php
/**
Template Name: My Custom Template
*/
include WP_PLUGIN_DIR.'/my-plugin/templates/my-template.php';
...while I'm sure there's a better way at it; this works quite well. If you want to get really fancy, you could also add something to the plugin's activation hook that copies this into the current theme.
本文标签: Custom Post Type template stored in plugin folder not showing in post attributes dropdown
版权声明:本文标题:Custom Post Type template stored in plugin folder not showing in post attributes dropdown 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745008153a2637387.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论