Your template_override()
function isn’t returning anything if your conditions aren’t met, which will break everything that doesn’t meet your conditions. You need to pass the existing template through:
function wpse_283378_template_override( $template ) {
// My conditions.
return $template;
}
add_filter('template_include', 'wpse_283378_template_override');
Also, is_post_type()
and template_override()
are very generic names for functions, which increases the risk of conflict with other plugins and themes, prefix them with something unique to your project.
Defining an is_post_type()
function is overkill anyway. Just replace is_single()
with is_singular( 'portfolio' )
:
function wpse_283378_template_override( $template ) {
if ( is_singular( 'portfolio' ) ) {
$new_template = locate_template( 'template-portfolio.php' );
if ( $new_template != '' ) {
return $new_template;
}
}
return $template;
}
add_filter('template_include', 'wpse_283378_template_override');
Note that I also checked that the template file exists before returning it, this way if it doesn’t it will fall back to the default instead of giving you a white screen.