• ferda2

    (@ferda2)


    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)
  • Hi @ferda2, sorry for the long delay.

    Here’s a doc you can use as a reference.

    Let us know if you need more help, otherwise please mark the topic as Resolved.

    Kind regards,
    Herman ??

Viewing 1 replies (of 1 total)
  • The topic ‘Custom template (page, post, custom content type)’ is closed to new replies.