[Support request] How to display the featured image of a parent page in all child pages?

Home Forums Support [Support request] How to display the featured image of a parent page in all child pages?

Home Forums Support How to display the featured image of a parent page in all child pages?

  • This topic has 1 reply, 2 voices, and was last updated 5 years ago by Tom.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #855037
    shpr

    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

    #855296
    Tom
    Lead Developer
    Lead Developer

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.