get_the_post_thumbnail_url

Return the post thumbnail URL.

Description

(string|false) get_the_post_thumbnail_url( (constant) $post = null, (string) $size = 'post-thumbnail' ); 

Returns (string|false)

Post thumbnail URL or false if no URL is available.

Parameters (2)

0. $post — Optional. (constant) => null
Post ID or WP_Post object. Default is global $post..
1. $size — Optional. (string) => 'post-thumbnail'
Registered image size to retrieve the source for or a flat array of height and width dimensions. Default post-thumbnail..

Usage

  1. if ( !function_exists( 'get_the_post_thumbnail_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-thumbnail-template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global `$post`. 
  5. $post = null; 
  6.  
  7. // Optional. Registered image size to retrieve the source for or a flat 
  8. // array of height and width dimensions. Default 'post-thumbnail'. 
  9. $size = 'post-thumbnail'; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = get_the_post_thumbnail_url($post, $size); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-thumbnail-template.php  
  1. function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { 
  2. $post_thumbnail_id = get_post_thumbnail_id( $post ); 
  3. if ( ! $post_thumbnail_id ) { 
  4. return false; 
  5. return wp_get_attachment_image_url( $post_thumbnail_id, $size );