admin管理员组文章数量:1130349
I am working on making a custom post type plugin for my website. However, I want to make it universal for any theme I may decide to change. Or to be able to append the post type to a single post file already.
It's a press release post type, and I am unable to find any guide to how to append or create a universal template file for the single post file.
Any guides or help would be much appreciated.
I am working on making a custom post type plugin for my website. However, I want to make it universal for any theme I may decide to change. Or to be able to append the post type to a single post file already.
It's a press release post type, and I am unable to find any guide to how to append or create a universal template file for the single post file.
Any guides or help would be much appreciated.
Share Improve this question edited Jan 4, 2019 at 2:44 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Jan 4, 2019 at 2:39 xensorxensor 11 Answer
Reset to default 1There re various filters you can use to inject your custom template. One being the template_include, the other single_template, and even type_template.
The easiest one would be single_template in your case (example from codex):
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'my_post_type') {
$single_template = dirname( __FILE__ ) . '/post-type-template.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_template' );
I am working on making a custom post type plugin for my website. However, I want to make it universal for any theme I may decide to change. Or to be able to append the post type to a single post file already.
It's a press release post type, and I am unable to find any guide to how to append or create a universal template file for the single post file.
Any guides or help would be much appreciated.
I am working on making a custom post type plugin for my website. However, I want to make it universal for any theme I may decide to change. Or to be able to append the post type to a single post file already.
It's a press release post type, and I am unable to find any guide to how to append or create a universal template file for the single post file.
Any guides or help would be much appreciated.
Share Improve this question edited Jan 4, 2019 at 2:44 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Jan 4, 2019 at 2:39 xensorxensor 11 Answer
Reset to default 1There re various filters you can use to inject your custom template. One being the template_include, the other single_template, and even type_template.
The easiest one would be single_template in your case (example from codex):
function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'my_post_type') {
$single_template = dirname( __FILE__ ) . '/post-type-template.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_template' );
本文标签: templatesHow do I find a way to create a global singlephp for a custom post type
版权声明:本文标题:templates - How do I find a way to create a global single.php for a custom post type? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749046911a2307991.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论