admin管理员组文章数量:1122826
I have implemented inside my plugin this hook to change the single template for custom post type (I do not want it to be in the child theme, just in my plugin) and it works just fine.
Now I want to implement content-single.php inside my plugin. How can it be done? This is the code that implements the custom template inside the plugin:
//Template fallback
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'my-custom-post-type') {
$single_template = dirname( __FILE__ ) . '/single-my-custom-post-type.php';
}
return $single_template;
}
add_filter( 'single_template', 'my-custom-post-type' );
I have implemented inside my plugin this hook to change the single template for custom post type (I do not want it to be in the child theme, just in my plugin) and it works just fine.
Now I want to implement content-single.php inside my plugin. How can it be done? This is the code that implements the custom template inside the plugin:
//Template fallback
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'my-custom-post-type') {
$single_template = dirname( __FILE__ ) . '/single-my-custom-post-type.php';
}
return $single_template;
}
add_filter( 'single_template', 'my-custom-post-type' );
Share
Improve this question
edited Feb 3, 2015 at 7:41
Gabriel
2,24810 gold badges22 silver badges24 bronze badges
asked Feb 3, 2015 at 7:20
DoriDori
1211 silver badge5 bronze badges
3
|
1 Answer
Reset to default 0In case anyone will want to do this, this is what worked for me:
In my single-my_custom_post_type.php
I replaced this line:
get_template_part('content', get_post_format());
With this one:
include 'content-spp_service_provider.php';
本文标签: Contentsinglephp inside my plugin
版权声明:本文标题:Content-single.php inside my plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281391a1926304.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
locate_template()
, if it's the second look atget_template_part()
. If it's neither, please can you clarify. – David Gard Commented Feb 3, 2015 at 10:18twentyfourteen
andtwentyfifteen
themes. – David Gard Commented Feb 3, 2015 at 16:02