Archived topic
How to display the featured image of a parent page in all child pages?
1 reply · Started by shpr on March 31, 2019
Hello,
can you tell me how I would do this in GeneratePress? I tried placing this code in functions.php (in a child theme) without any luck.
function get_parent_post_thumb($post){
if ( $post->post_parent ) {
$parentId = end($post->ancestors);
the_post_thumbnail($parentId);
} else {
the_post_thumbnail($post->ID);
}
}
Code source: https://www.isitwp.com/get-parent-featured-image-in-children-subpage/
Thanks
Hi there,
Did you use the get_parent_post_thumb() function anywhere on your site? Maybe in a Hook Element? It looks like that function actually outputs an image, so it needs to be placed where you want the image to be.
