WordPress at a glance

wp_get_attachment_thumb_url() WP 1.0

Retrieve URL for an attachment thumbnail.

Works based on: image_downsize()
✈ 1 time = 0.001119s = very slow | 50000 times = 6.09s = fast | PHP 7.0.8, WP 4.6
Hooks from the function
Return

String/false. False on failure. Thumbnail URL on success.

Usage

wp_get_attachment_thumb_url( $post_id );
$post_id(int)
Attachment ID.
Default: 0

Changelog

Since 2.1.0 Introduced.

Code of wp get attachment thumb url: wp-includes/post.php WP 5.2.2

<?php
function wp_get_attachment_thumb_url( $post_id = 0 ) {
	$post_id = (int) $post_id;
	if ( ! $post = get_post( $post_id ) ) {
		return false;
	}
	if ( ! $url = wp_get_attachment_url( $post->ID ) ) {
		return false;
	}

	$sized = image_downsize( $post_id, 'thumbnail' );
	if ( $sized ) {
		return $sized[0];
	}

	if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) {
		return false;
	}

	$url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url );

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

Related Functions

From tag: Thumbnail (images)

More from category: Thumbnails

No comments
    Hello, !     Log In . Register