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

Custom Post Type template stored in plugin folder not showing in post attributes dropdown

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

The 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

  1. Place the template in the root theme / child theme folder or
  2. 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.

发布评论

评论列表(0)

  1. 暂无评论