// Template include.
add_filter('template_include', [$this, 'template'] );
// Register the template for the 'course' post type
function template($template) {
// Course single.
if (is_singular('course')) {
$template = SABER_LMS_PATH . 'templates/single-course.php';
}
// Question single.
if (is_singular('question')) {
$template = SABER_LMS_PATH . 'templates/single-question.php';
}
return $template;
}
In a WordPress plugin we can use template_include filter to provide a default template that will be used under various conditions. The most common condition would be to provide a single post template for a custom post type that the plugin registers. Another common condition is to provide an archive template for a taxonomy or post type archive that the plugin registers.