How to get featured image url of a post or pages

In this post we are going to learn about wordpress get featured image url now start step by step

First get the id of the post or page of which featured image url you want to get by using the code $post->ID

Second get the id of the thumbnail image by passing the post id through the function get_post_thumbnail_id($post->ID)

Third get the attachment url and print that by passing the thumb id through the function wp_get_attachment_url( get_post_thumbnail_id($post->ID))

Now here is the full code:

<?php
$post_id = $post->ID;
$post_thumb_id = get_post_thumbnail_id($post_id);
$attachment_img_url = wp_get_attachment_url( $post_thumb_id );
?>
<img class=”img-responsive” src=”<?php echo $attachment_img_url; ?>” />

Thanks for Reading

Share The Post On -

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.