Actually, I noticed that your closure is not capturing/using the proper $template
variable which is passed from the template_include
filter hook:
// This hook is defined in wp-includes/template-loader.php
$template = apply_filters( 'template_include', $template )
The closure is also not returning the template..
So your closure should look like:
add_filter( 'template_include', function( $template ) use ( $custom_resource_single ) {
return custom_resource_single( $custom_resource_single, $template );
} );
But you may want to pass the $custom_resource_single
by reference (use ( &$custom_resource_single )
) in case it gets changed after the above closure:
if ( $blog_id == 5 ) {
$custom_resource_single="single-resource-alt.php";
}
add_filter( 'template_include', function( $template ) use ( &$custom_resource_single ) {
return custom_resource_single( $custom_resource_single, $template );
} );
// $custom_resource_single is changed here.
if ( /* condition */ ) {
$custom_resource_single="file.php";
}