Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the image source from get_the_post_thumbnail($post->ID);

I have to get the image source from the code below.

  $thumburl = get_the_post_thumbnail($post->ID);

Here I'm getting

<img width="325" height="202" src="http://localhost/TantraProjects/Border-fall/Repo/WebApp/wp-content/uploads/2012/12/film.png" class="attachment-post-thumbnail wp-post-image" alt="film" title="film">

I want to get this part.

"http://localhost/TantraProjects/Border-fall/Repo/WebApp/wp-content/uploads/2012/12/film.png"

How can I get the source ?

like image 316
Ranjit Avatar asked Jan 16 '13 13:01

Ranjit


People also ask

How do you get a post featured image?

Using the built-in WordPress function get_the_post_thumbnail() to display the featured image of a post in a <img> tag. This is the easiest way to display a post's featured image in a WordPress loop.

How do I get the post featured image URL in WordPress?

To simply display the featured image itself, you can use the get_the_post_thumbnail function. If you specifically need the featured image URL, you can copy and paste the following code snippet into your template file: echo get_the_post_thumbnail_url(get_the_ID(),'medium');

How do I find the thumbnail ID of a post?

get_post_thumbnail_id( int|WP_Post $post = null ): int|false. Retrieves the post thumbnail ID.

How do I find the post ID in WordPress?

You can also find the post ID in the WordPress editor, which you get to by clicking on the post you want. When done this way, the post ID is in the address bar. The URL shown will be exactly the same, and the post ID is again sandwiched between the “post=” and the “&.”


2 Answers

$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
like image 160
Mustafa Shujaie Avatar answered Oct 21 '22 16:10

Mustafa Shujaie


This is what you want, more concise:

get_the_post_thumbnail_url($post->ID, $size);

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

You can get the url for any thumbnail size, so its quite a useful function.

like image 37
filtah Avatar answered Oct 21 '22 16:10

filtah