[Resolved] Featured image at the top

Home Forums Support [Resolved] Featured image at the top

Home Forums Support Featured image at the top

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #691231
    Tomasz

    How do I put a featured image above an element header on a blog post site? I tried to set the featured image in the customiser but it didn’t work (all the other featured image settings work). I also tried to set the featured image in the element header options, but then it appears as a background – which I don’t want.

    GP Premium 1.7.2
    #691353
    David
    Staff
    Customer Support

    Hi there,

    you could use this function to create a shortcode for displaying the featured image:

    add_shortcode('featured_img', 'fi_in_content');
    
    function fi_in_content($atts) {
        global $post;
        return get_the_post_thumbnail($post->ID);
    }

    Just add [featured_img] to your Header Element content

    #691408
    Tomasz

    Hey, I think we are on a good way but I might be doing something wrong here because I just get a plain text message: “[featured_img]” instead of an image.
    The function I have added as a new hook element (before_header, execute php, display location: post).
    The shortcode I have just pasted where I want it to be…

    #691411
    Tomasz

    Also now I see that the function plain text is being displayed. Not good.

    #691437
    David
    Staff
    Customer Support

    If you’re using the Hook element you need to check the Execute Shortcode box

    #691441
    Tomasz

    OK. Checked the Execute Shortcode option in the hook element. No change.

    #691453
    David
    Staff
    Customer Support

    You need to add the function to your child theme function file of use the code snippets plugin:

    https://docs.generatepress.com/article/adding-php/

    And then only add the shortcode to the hook or header

    #691488
    Tomasz

    OK, got it. I thought that I don’t need snippets plugin if there is a hook element feature.
    Thanks, it’s all working now.

    #691499
    David
    Staff
    Customer Support
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.