Title: wp_get_attachment_thumb_file
Published: April 25, 2014
Last modified: April 28, 2025

---

# wp_get_attachment_thumb_file( int $post_id ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#wp--skip-link--target)

This function has been deprecated since 6.1.0.

Retrieves thumbnail for an attachment.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#description)󠁿

Note that this works only for the (very) old image metadata style where ‘thumb’ 
was set, and the ‘sizes’ array did not exist. This function returns false for the
newer image metadata style despite that ‘thumbnail’ is present in the ‘sizes’ array.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#parameters)󠁿

 `$post_id`intoptional

Attachment ID. Default is the ID of the global `$post`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#return)󠁿

 string|false Thumbnail file path on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#source)󠁿

    ```php
    function wp_get_attachment_thumb_file( $post_id = 0 ) {
    	_deprecated_function( __FUNCTION__, '6.1.0' );

    	$post_id = (int) $post_id;
    	$post    = get_post( $post_id );

    	if ( ! $post ) {
    		return false;
    	}

    	// Use $post->ID rather than $post_id as get_post() may have used the global $post object.
    	$imagedata = wp_get_attachment_metadata( $post->ID );

    	if ( ! is_array( $imagedata ) ) {
    		return false;
    	}

    	$file = get_attached_file( $post->ID );

    	if ( ! empty( $imagedata['thumb'] ) ) {
    		$thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
    		if ( file_exists( $thumbfile ) ) {
    			/**
    			 * Filters the attachment thumbnail file path.
    			 *
    			 * @since 2.1.0
    			 *
    			 * @param string $thumbfile File path to the attachment thumbnail.
    			 * @param int    $post_id   Attachment ID.
    			 */
    			return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
    		}
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/deprecated.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/deprecated.php#L4346)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/deprecated.php#L4346-L4381)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_get_attachment_thumb_file’, string $thumbfile, int $post_id )](https://developer.wordpress.org/reference/hooks/wp_get_attachment_thumb_file/)

Filters the attachment thumbnail file path.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata/)`wp-includes/post.php` |

Retrieves attachment metadata for attachment ID.

  | 
| [get_attached_file()](https://developer.wordpress.org/reference/functions/get_attached_file/)`wp-includes/post.php` |

Retrieves attached file path based on attachment ID.

  | 
| [wp_basename()](https://developer.wordpress.org/reference/functions/wp_basename/)`wp-includes/formatting.php` |

i18n-friendly version of basename().

  | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_attachment_thumb_file/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Deprecated.  | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_attachment_thumb_file%2F)
before being able to contribute a note or feedback.