wp_get_attachment_thumb_url()WP 2.1.0

Retrieve URL for an attachment thumbnail.

1 time — 0.001119 sec (very slow) | 50000 times — 6.09 sec (fast) | PHP 7.0.8, WP 4.6
Hooks from the function

Return

String|false. Thumbnail URL on success, false on failure.

Usage

wp_get_attachment_thumb_url( $post_id );
$post_id(int)
Attachment ID.
Default: ID of the global $post

Examples

0

#1 Get a link to the thumbnail size of the image

Let's say we have an image with ID 7412 in the media library and we need to get a URL to its thumbnail (the smallest size):

$thumburl = wp_get_attachment_thumb_url( 7412 );

echo $thumburl; //> http://example.com/wp-content/uploads/2016/09/Upravlenie-setyu-80x80.png

Changelog

Since 2.1.0 Introduced.
Since 6.1.0 Changed to use wp_get_attachment_image_url().

wp_get_attachment_thumb_url() code WP 6.5.2

function wp_get_attachment_thumb_url( $post_id = 0 ) {
	$post_id = (int) $post_id;

	/*
	 * This uses image_downsize() which also looks for the (very) old format $image_meta['thumb']
	 * when the newer format $image_meta['sizes']['thumbnail'] doesn't exist.
	 */
	$thumbnail_url = wp_get_attachment_image_url( $post_id, 'thumbnail' );

	if ( empty( $thumbnail_url ) ) {
		return false;
	}

	/**
	 * Filters the attachment thumbnail URL.
	 *
	 * @since 2.1.0
	 *
	 * @param string $thumbnail_url URL for the attachment thumbnail.
	 * @param int    $post_id       Attachment ID.
	 */
	return apply_filters( 'wp_get_attachment_thumb_url', $thumbnail_url, $post_id );
}