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.
There 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' );