Inherit Featured Image

If you’d like to continue using the_post_thumbnail in your theme, but do not want to use a fixed default, use this snippet to inherit images from parent pages.

global $post;

if ( has_post_thumbnail() ) {

	the_post_thumbnail();

} else {

	echo get_the_post_thumbnail($post->post_parent);

}

Update, December 15, 2015

Inherit the_post_thumbnail from ancestor:

global $post;

$parents = get_post_ancestors( $post->ID );

/* Get the ID of the 'top most' Page if not return current page ID */

$id = ($parents) ? $parents[count($parents)-1]: $post->ID;

if(has_post_thumbnail( $id )) {

	echo get_the_post_thumbnail( $id, 'full');

}

 

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.