wordpresswordpress-featured-image

Pulling Single Post Featured Image under a Category List


I have this code in my child theme but it's pulling in the category featured image instead of the individual single posts image, when viewing a list of single post under category. The code is within a loop.

  <?php if (has_post_thumbnail())  { ?>
    <?php the_post_thumbnail( "full" ); ?>
  <?php } ?>

Solution

  • If anybody gets caught up on retreiving an image outside of a single post this solution worked for me.

    <img src="<?php $image_source = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); echo $image_source[0]; ?>">
    

    The $post->ID may have to change depending on what you're working on.