Get featured image on Blog Index


I’ve been trying to use the “featured image” from the home (the blog index) with no luck. It’s working for every single page, but it’s not working for the home.

The code looks something like this:

// Don't use on single posts
    if (!is_single()) {
        if (is_home()) {
            if (function_exists('wp_get_attachment_thumb_url')) {
                $img = wp_get_attachment_image_src(get_post_thumbnail_id(),'full');
                $featured_image = $img[0];
        } else {
            if (function_exists('wp_get_attachment_thumb_url') && has_post_thumbnail()) {
                $img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');
                $featured_image = $img[0];
        if ($featured_image) { ?>
            // A lot of code...
        <?php }

I already tried to obtain the thumbnail using the _thumbnail_id meta. Same result.

This code is placed on the functions file, I believe that the issue is that it’s trying to get the loop/posts featured image.

Thanks a lot in advance.

demogar 3 years 2020-04-02T08:50:55-05:00 0 Answers 89 views 0

Leave an answer