wp_get_attachment_thumb_file

Retrieve thumbnail for an attachment.

Description

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

Returns (string|false)

False on failure. Thumbnail file path on success.

Parameters (1)

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

Usage

  1. if ( !function_exists( 'wp_get_attachment_thumb_file' ) ) { 
  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_file($post_id); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function wp_get_attachment_thumb_file( $post_id = 0 ) { 
  2. $post_id = (int) $post_id; 
  3. if ( !$post = get_post( $post_id ) ) 
  4. return false; 
  5. if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) 
  6. return false; 
  7.  
  8. $file = get_attached_file( $post->ID ); 
  9.  
  10. if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) { 
  11. /** 
  12. * Filters the attachment thumbnail file path. 
  13. * @since 2.1.0 
  14. * @param string $thumbfile File path to the attachment thumbnail. 
  15. * @param int $post_id Attachment ID. 
  16. */ 
  17. return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); 
  18. return false;