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 bypassing the post id through the function get_post_thumbnail_id($post->ID)

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

Now here is the full code:

$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 -