Site logo

Archived topic

How can I get Featured Image In Sections

1 reply · Started by Het on October 14, 2020

Viewing posts 1–2 of 2

Basically I am using sections and of course the featured image disappeared. Any way I can use featured image? This piece of code in my child theme doesn't seem to work/the shortcode.

function fun_featured_image() {

ob_start();?>
global $post;
<?php $featured_img_url = get_the_post_thumbnail_url();?>
" alt="<?php the_title(); ?>">

<?php return ob_get_clean();
}

Hi,

Some html tags are missing from your code.

Try this out:

add_shortcode( 'fun_featured_image', function() {
ob_start();
global $post;
$featured_img_url = get_the_post_thumbnail_url($post->id);
echo '<img src="'.$featured_img_url.'" alt="'.get_the_title($post->id).'"/>';
return ob_get_clean();
});

You can then use the shortcode [fun_featured_image] to display your featured image.

This archived topic is closed to new replies.