最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Call featured image url

matteradmin3PV0评论

How do I get the URL of my featured image?

I am using buffy and I can Call The URL of The post and so on, but can't figure out how to Call The URL of The featured image.

How do I get the URL of my featured image?

I am using buffy and I can Call The URL of The post and so on, but can't figure out how to Call The URL of The featured image.

Share Improve this question edited Dec 31, 2014 at 14:42 Howdy_McGee 20.9k24 gold badges91 silver badges177 bronze badges asked Dec 31, 2014 at 12:49 danielnndanielnn 11 bronze badge 1
  • you can learn about please visit wordpress.stackexchange/questions/76954/… – Dharmishtha Patel Commented Jun 26, 2018 at 5:19
Add a comment  | 

3 Answers 3

Reset to default 1

the_post_thumbnail() is highest level function for it, which will output complete HTML. If you need some lower level parts, digging deeper are nested:

  • get_the_post_thumbnail()
  • wp_get_attachment_image()
  • wp_get_attachment_image_src()

Hey by using wp_get_attachment_image_src() to get the featured image url like this

<?php 
    if ( has_post_thumbnail() ) {
        $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
    }
?>

<img src="<?php echo $large_image_url[0]; ?>">

You can simply call the following function to get the url of the featured image depending on the size you want to print :

the_post_thumbnail_url( $size );

the size variable might be either a string : (thumbnail, medium, large, full) or a precisized width and height (24*24).

You can learn more about it by visiting this url : https://codex.wordpress/Function_Reference/the_post_thumbnail_url

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far