How to Get Wordpress Child Pages to Inherit a Parent Page’s Featured Image – Genesis Style.

Here’s a quick recipe for making this happen. I have it appearing just before the Page content, but it could work in other hook spots, such as genesis_before_content or other hooks that you can see here. Keep in mind that any Page that’s an ancestor of the one with the Featured Image will inherit the one at the top, so it’s sort of brute force, but can be really handy if someone wants one image all over a particular section, so to speak.

Also, notice “full” down below under get_the_post_thumbnail. You may want “thumbnail” instead of “full” for a smaller version of the image, for instance. And you may want to use a less silly function name than I used. 🙂

This code would go in your theme’s functions.php, but you knew that! Enjoy!

I slightly modified the code as per a coder’s suggestion to remove a global variable.

add_action( 'genesis_before_post', 'dc_blah_feat' );
function dc_blah_feat () {
    if( is_page() ) { 
        $parents = get_post_ancestors( get_the_ID() );
        $id = ($parents) ? $parents[count($parents)-1]: $post->ID;
        echo get_the_post_thumbnail($id, 'full');
    }
}

Speaking of Genesis, here’s a very modern theme with cool scrolling that is extremely popular: Parallax Pro.

I am a Genesis affiliate. This means that if you buy it from my link above, I will get a small commission. It’s easy to recommend Genesis themes, because they’re uniformly excellent. The Genesis framework is my primary site-building tool.

4 Comments


  1. Plugged this in and it worked like a charm. Less than 10 lines of code – beautiful! Thank you, David!

    Reply

    1. Carrie,
      Beautiful, glad to hear it! And I’d be remiss if I didn’t mention that you, Carrie, inspired me to write this. 🙂
      Dave

      Reply

  2. You are Amazing! I spent so long trying to get this function for genesis, you saved me.

    Reply

  3. Nancy,
    Yay! Glad to hear it. It could definitely save some data entry time. Come to think of it, it could be handy for setting up demos where you want something in the photo slot, but don’t need a unique photo on every page.

    Dave

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *