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
.
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.