Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to get a post featured image url. I have gone through a code on WPbeginner and i have exactly pasted the same code inside the loop but it's not working.

What I have tried:

<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_getattachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>
Posted
Updated 5-Feb-18 21:51pm

Yeah i have put the code in the loop but still having issues.
 
Share this answer
 
<?php 
$wpblog_fetrdimg = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
?>
<div class="wpblog-featured-image"
    <?php if( $wpblog_fetrdimg ) : ?>
     style="wpblog-featured-background-image: url(<?php echo $wpblog_fetrdimg; ?>);"
    <?php endif; ?>
        >
  </div>



See if this works.
 
Share this answer
 
Comments
randypaull 6-Feb-18 3:54am    
Can you please provide me a complete code ?
At first glance, I don't see any problem with the code. Are you sure you have applied it within the loop? Sometimes it's tricky.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900