Skip to content

Commit

Permalink
fix: templates/wordpress/functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xaxaxixd committed Jan 10, 2024
1 parent 4601bcd commit f3dbdda
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions templates/wordpress/theme/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,23 @@ function filter_ptags_on_images($content){
function getIdBySlug($page_slug) {
return get_page_by_path($page_slug)->ID;
}

add_filter(
'page_template',
function ($template) {
global $post;
if ($post->post_parent) {
$parent = get_post(
reset(array_reverse(get_post_ancestors($post->ID)))
);
$child_template = locate_template(
[
'page-'.$parent->post_name.'-'.$post->post_name.'.php',
'page-'.$parent->post_name.'-page.php',
]
);
if ($child_template) return $child_template;
}
return $template;
}
);

0 comments on commit f3dbdda

Please sign in to comment.