Archived topic
Featured image shortcode
5 replies · Started by gedosan on October 31, 2018
Hi guys
I want to control where my featured images appear in posts. I'm assuming there's a shortcode that I can add to the post for this...I tried '[featured_img]' but it didn't pull through the image?
Thanks
G
Hi there,
GP doesn't include any shortcode functions, but here is a PHP snippet you can add for that exact shortcode:
add_shortcode('featured_img', 'fi_in_content');
function fi_in_content($atts) {
global $post;
return get_the_post_thumbnail($post->ID);
}
any chance you can tweak the code so if the shortcode is detected, the page doesn't show the featured image at top of the page.
Basically, I want to have featured images on ALL posts but on certain posts have the featured image slightly further down the page (by placing the shortcode in the WP editor). As things stand, I get two featured images when I do this :-)
Thanks
If you're manually adding the short code then you can use the disable elements meta box to remove the templated featuered image:
https://docs.generatepress.com/article/disable-elements-overview/
great thanks
you're welcome