[Support request] How can I get Featured Image In Sections

Home Forums Support How can I get Featured Image In Sections

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1489430
    Het

    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();
    }

    #1489452
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

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