admin管理员组

文章数量:1025278

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

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

本文标签: phpCall featured image url