banner-image

Display post thumb image URL using custom functions

When we try to convert a normal HTML website to a custom WordPress theme template, sometimes we need to call or display the post thumb image using a custom function.

Here are some custom functions/methods to follow to do the same. To display post thumb image using image SRC

<!--Post Thumbnail Url-->
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id()); ?>" alt="">

Another method to do that..

<?php $image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' );?>
<img src="<?php echo $image_attributes[0]; ?>" alt="slide1">

If you want to display the post thumb image with that particular post thumb image URL, then follow the below method.

$thumb_id = ;
$thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id(),'thumbnail-size', true);

<a href="<?php echo $thumb_url[0];?>"><?php the_post_thumbnail(array(500, 500));?></a>

Do You Want To Boost Your Business?

drop us a line and keep in touch