Можно дописать в functions.php своей темы новую логику подключения шаблонов:
https://wp-kama.ru/hook/template_includeadd_filter( 'template_include', 'portfolio_page_template', 99 );
function portfolio_page_template( $template ) {
if( is_page('portfolio') ){
if ( $new_template = locate_template( array( 'portfolio-page-template.php' ) ) )
$template = $new_template ;
}
return $template;
}
Или полностью переписать ее:
https://wp-kama.ru/hook/template_redirect<?php
namespace Oxboot\Theme;
use Brain\Hierarchy\Hierarchy;
use duncan3dc\Laravel\BladeInstance;
use Twig_Loader_Filesystem;
use Twig_Environment;
class View
{
public function __construct($config)
{
add_action('template_redirect', function () use ($config) {
$templates = (new Hierarchy())->getTemplates();
$template_engines = $config['view']['template_engines'];
foreach ($templates as $template) {
foreach ($template_engines as $template_engine => $template_extension) {
$path = OX_THEME_VIEWS."/{$template}{$template_extension}";
if (file_exists($path)) {
switch ($template_engine) {
case 'Blade':
$blade = new BladeInstance(OX_THEME_VIEWS, OX_THEME_CACHE.'/blade');
echo $blade->render($template);
break;
case 'Twig':
$loader = new Twig_Loader_Filesystem(OX_THEME_VIEWS);
$twig = new Twig_Environment($loader, ['cache' => OX_THEME_CACHE.'/twig']);
echo $twig->render($template.$template_extension);
break;
case 'PHP':
require $path;
}
exit;
}
}
}
});
}
}