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?

up vote 2 down vote accepted

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' );
  • Thanks. By the way, I also installed the "Featured Image Caption" plugin - would it be easy to make this inherit the captions too? – meder omuraliev Nov 15 '14 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 '14 at 0:38

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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