Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

How to add featured image to a page header?

  • I’m working with the Wellbeing template and I cannot figure out how to get the page hero to show the featured image instead of a static background image. I used to know, but the settings have changed.

    For the ‘Page Hero – Pages’ element, I tried putting {{featured_image key:url}} into the Inline Background Image field for the main Section container but it’s not working like it does for the Section container in the ‘Template – Single Post’ element. Why is this?

    I did add a featured image to the About page, and it’s displaying below the header.

  • Hi there,

    It should work.

    Can you provide an admin login and let me know which element it is?

    Your site is in maintenance mode. I can not see any content.

    Let me know 🙂

  • Here you go.

  • You have a static image set as a background image, it overrides the dynamic bg image:
    https://app.screencast.com/rTgbbe03gO69e

  • I see. How would I make a ‘default’ bg image for pages that don’t have a Featured Image set?

  • Try this, replace 100 with the actual fallback image ID.

    function add_fallback_featured_image($value, $post_id, $meta_key, $single) {
        // Check if we're retrieving the post thumbnail
        if ($meta_key === '_thumbnail_id' && !$value) {
            // Set your fallback featured image ID
            return '100'; // Return fallback ID if no thumbnail is set
        }
    
        // Return the original value if it's already set
        return $value;
    }
    
    // Hook into get_post_metadata for the _thumbnail_id meta key
    add_filter('get_post_metadata', 'add_fallback_featured_image', 10, 4);
  • Thanks Ying. Will that create a fallback for place there’s an image? How would I make it specific to an element?

  • This code create a fallback featured image for all posts and pages.

    How would I make it specific to an element?

    so you only want it to apply to pages? If so, you can add a is_page() condition to the code.

    function add_fallback_featured_image($value, $post_id, $meta_key, $single) {
        // Check if we're retrieving the post thumbnail
        if ($meta_key === '_thumbnail_id' && !$value && is_page()) {
            // Set your fallback featured image ID
            return '100'; // Return fallback ID if no thumbnail is set
        }
    
        // Return the original value if it's already set
        return $value;
    }
    
    // Hook into get_post_metadata for the _thumbnail_id meta key
    add_filter('get_post_metadata', 'add_fallback_featured_image', 10, 4);
  • Got it, thank you!

  • You are welcome   🙂

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