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 ?
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.
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');
get_post_thumbnail_id( int|WP_Post $post = null ): int|false. Retrieves the post thumbnail ID.
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 “&.”
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With