Skip to content

Commit

Permalink
🩹 Only prioritize block templates in block themes (#368)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Daniel Sturm <384815+dsturm@users.noreply.github.com>
  • Loading branch information
Log1x and dsturm authored Apr 2, 2024
1 parent a6c14b2 commit 5e80f30
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,28 @@ trait FiltersTemplates
*/
public function filterTemplateHierarchy($files)
{
$templates = [...$this->sageFinder->locate($files), ...$files];
$templates = $this->sageFinder->locate($files);

if (
! function_exists('wp_is_block_theme') ||
! wp_is_block_theme() ||
! current_theme_supports('block-templates')
) {
return [...$templates, ...$files];
}

$pages = [];

if ($template = get_page_template_slug()) {
$pages = array_filter(
$templates,
fn ($file) => str_contains($file, $template)
);

$templates = array_diff($templates, $pages);
}

return ! current_theme_supports('block-templates')
? $templates
: array_reverse($templates);
return [...$pages, ...$files, ...$templates];
}

/**
Expand Down

0 comments on commit 5e80f30

Please sign in to comment.