wp_get_attachment_thumb_url

The timeline below displays how wordpress function wp_get_attachment_thumb_url has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Retrieves URL for an attachment thumbnail.
 *
 * @since 2.1.0
 * @since 6.1.0 Changed to use wp_get_attachment_image_url().
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false Thumbnail URL on success, false on failure.
 */
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);
}

WordPress Version: 6.1

/**
 * Retrieves URL for an attachment thumbnail.
 *
 * @since 2.1.0
 * @since 6.1.0 Changed to use wp_get_attachment_image_url().
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false Thumbnail URL on success, false on failure.
 */
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);
}

WordPress Version: 5.9

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
 * @return string|false Thumbnail URL on success, false on failure.
 */
function wp_get_attachment_thumb_url($post_id = 0)
{
    $post_id = (int) $post_id;
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $url = wp_get_attachment_url($post->ID);
    if (!$url) {
        return false;
    }
    $sized = image_downsize($post_id, 'thumbnail');
    if ($sized) {
        return $sized[0];
    }
    $thumb = wp_get_attachment_thumb_file($post->ID);
    if (!$thumb) {
        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);
}

WordPress Version: 5.7

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false Thumbnail URL on success, false on failure.
 */
function wp_get_attachment_thumb_url($post_id = 0)
{
    $post_id = (int) $post_id;
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $url = wp_get_attachment_url($post->ID);
    if (!$url) {
        return false;
    }
    $sized = image_downsize($post_id, 'thumbnail');
    if ($sized) {
        return $sized[0];
    }
    $thumb = wp_get_attachment_thumb_file($post->ID);
    if (!$thumb) {
        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);
}

WordPress Version: 5.3

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail URL on success.
 */
function wp_get_attachment_thumb_url($post_id = 0)
{
    $post_id = (int) $post_id;
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    $url = wp_get_attachment_url($post->ID);
    if (!$url) {
        return false;
    }
    $sized = image_downsize($post_id, 'thumbnail');
    if ($sized) {
        return $sized[0];
    }
    $thumb = wp_get_attachment_thumb_file($post->ID);
    if (!$thumb) {
        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);
}

WordPress Version: 5.2

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail URL on success.
 */
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);
}

WordPress Version: 4.6

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail URL on success.
 */
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(basename($url), 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);
}

WordPress Version: 4.3

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail URL on success.
 */
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(basename($url), basename($thumb), $url);
    /**
     * Filter 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);
}

WordPress Version: 4.0

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|bool False on failure. Thumbnail URL on success.
 */
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(basename($url), basename($thumb), $url);
    /**
     * Filter 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);
}

WordPress Version: 3.9

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID
 * @return string|bool False on failure. Thumbnail URL on success.
 */
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(basename($url), basename($thumb), $url);
    /**
     * Filter 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);
}

WordPress Version: 3.7

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID
 * @return string|bool False on failure. Thumbnail URL on success.
 */
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(basename($url), basename($thumb), $url);
    return apply_filters('wp_get_attachment_thumb_url', $url, $post->ID);
}