So I am writing a plugin and I am wanting to assign a custom template that exist within my plugin directory to a registered CPT (features). I have cpt-features-template.php as the file name located in my plugin folder root.
Can I do something like:
add_filter('single_template', function($original){
global $post;
//$post_name = $post->post_name;
$post_type = $post->post_type;
$base_name = 'custom-' . $post_type . '-template.php';
$template = locate_template($base_name);
if ($template && ! empty($template)) return $template;
return $original;
});
Above code referenced from Can I assign a template to a custom post type?
cpt-features-template.php
is in your plugin directory ?