0

Basically I'm looking to share the same featured image across multiple sub pages under their respective primary page.

Is there any plugin that lets me do this, so they can inherit a featured image?

1 Answer 1

2

You could easily do this by hooking into the save_post action and updating the featured image custom field. In your functions.php file, add the following code:

function interit_featured_image( $post_id ) {

    // Get Parent ID
    $parent_id = wp_get_post_parent_id( $post_id );

    // Only proceed if this page has a parent
    if ($parent_id != 0) :

        // Get Parent Thumbnail
        $parent_thumbnail = get_post_meta( $parent_id, '_thumbnail_id', true );

        // Get Parent Caption Data (for the other plugin)
        $parent_caption = get_post_meta( $parent_id, '_cc_featured_image_caption', true );

        // Set Thumbnail
        update_post_meta( $post_id, '_thumbnail_id', $parent_thumbnail );

        // Set Caption (again, for the other plugin)
        update_post_meta( $post_id, '_cc_featured_image_caption', $parent_caption );


    endif;

}
add_action( 'save_post', 'interit_featured_image' );
2
  • Thanks. By the way, I also installed the "Featured Image Caption" plugin - would it be easy to make this inherit the captions too? Nov 15, 2014 at 0:20
  • I've not used the plugin before, but I just downloaded it and it looks like it stores everything in another custom field. I've updated the answer to include this field, so you can give it a shot. It's not tested, so let me know if this works or not. Good luck.
    – BODA82
    Nov 15, 2014 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.