Archived topic
Featured image at the top
8 replies · Started by Tomasz on October 1, 2018
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.
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
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...
Also now I see that the function plain text is being displayed. Not good.
If you're using the Hook element you need to check the Execute Shortcode box
OK. Checked the Execute Shortcode option in the hook element. No change.
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
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.
Thats great.