wp_get_attachment_thumb_url

Retrieve URL for an attachment thumbnail.

Description

(string|false) wp_get_attachment_thumb_url( (int) $post_id = 0 ); 

Returns (string|false)

False on failure. Thumbnail URL on success.

Parameters (1)

0. $post_id — Optional. (int)
Attachment ID. Default 0.

Usage

  1. if ( !function_exists( 'wp_get_attachment_thumb_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Attachment ID. Default 0. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_get_attachment_thumb_url($post_id); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function wp_get_attachment_thumb_url( $post_id = 0 ) { 
  2. $post_id = (int) $post_id; 
  3. if ( !$post = get_post( $post_id ) ) 
  4. return false; 
  5. if ( !$url = wp_get_attachment_url( $post->ID ) ) 
  6. return false; 
  7.  
  8. $sized = image_downsize( $post_id, 'thumbnail' ); 
  9. if ( $sized ) 
  10. return $sized[0]; 
  11.  
  12. if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) 
  13. return false; 
  14.  
  15. $url = str_replace(basename($url), basename($thumb), $url); 
  16.  
  17. /** 
  18. * Filters the attachment thumbnail URL. 
  19. * @since 2.1.0 
  20. * @param string $url URL for the attachment thumbnail. 
  21. * @param int $post_id Attachment ID. 
  22. */ 
  23. return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );