4

How to get the php template file from other theme folder?


For Example :

My Current Theme Folder is promax . Im working on archive.php and want to include a template file inside of archive.php from other folder called child theme promax-child' and a folder inside called includes has a file archive-desc.php.

1 Answer 1

2

You can filter the template with the template_include filter. This example will filter the archive template for all archive pages. If you need to do this for a specific archive, use is_post_type_archive( $post_types ) as your condition. Put this in your functions.php file of your child theme.

function my_archive_filter( $template) {
    if ( is_archive() ) {
        return 'path/to/includes/archive-desc.php'; // Path to your child theme template.
    }
    else {
        return $template;
    }
}

apply_filters( 'template_include', 'my_archive_filter' );

Edit: It should now fall back to the default template if the custom template fails for some reason.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.