wp_get_attachment_thumb_file() WordPress Function

The wp_get_attachment_thumb_file() function is used to get the thumbnail image for an attachment. It returns the path to the thumbnail image file.

wp_get_attachment_thumb_file( int $post_id ) #

Retrieve thumbnail for an attachment.


Parameters

$post_id

(int)(Optional) Attachment ID. Default is the ID of the global $post.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/post.php

function wp_get_attachment_thumb_file( $post_id = 0 ) {
	$post_id = (int) $post_id;
	$post    = get_post( $post_id );

	if ( ! $post ) {
		return false;
	}

	$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;
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More