Custom template (page, post, custom content type)
-
Hi, I want to create custom templates in a child theme. What is the correct procedure? For example, I created single-test.php (for test category) and put the code in function.php:
add_filter( ‘single_template’, ‘my_single_template’ );
function my_single_template($single_template)
{
if (in_category(1)) {
$file = get_template_directory().’/single-test.php’;
if ( file_exists($file) ) {
return $file;
}
}
return $single_template;
}Is this the right way or is it better to work with template-parts/content-single.php (template-parts/single/…) files?
Thank you
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom template (page, post, custom content type)’ is closed to new replies.