get featured image url by post id – How to get WordPress post featured image URL?

get featured image url by post id & WordPress gives you the function get_post_thumbnail_id to get the ID of an image. Get Featured Image URL – get featured image post wordpress by post id

get featured image url by post id

featured images are pretty useful and pretty simply to use in WordPress. you can also check this article for Woocommerce Get Featured Image Url And Gallery Images

Also Read This 👉   Send WhatsAPP Message API using PHP Step By Step

Getting a Post’s Featured Image URL By Post ID

<?php $featured_img = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

<img src="<?php echo $featured_img; ?>" width="100" height="120" />

If Featured Image else your default image:

check below PHP Source code:

<?php $featured_img = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

<?php if($featured_img) {?>
<img src="<?php echo $featured_img; ?>" width="100" height="120" />
<?php } else {?>
<img src="logo_default.jpg" width="100" height="120" />
<?php } ?>

get featured image url

echo get_the_post_thumbnail_url();

How to get WordPress Post Featured Image URL in PHP?

Display the featured post URL (you can replace ‘medium’, ‘large’ with a different image size)

echo get_the_post_thumbnail_url( get_the_ID(), 'medium' );

Don’t Miss : Woocommerce Get product image url

Also Read This 👉   php mysql multiple choice quiz source code Example - How to create a multiple choice quiz in PHP and MySQL?

I hope you get an idea about get featured image url by post id.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.