wp_get_attachment_link

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

WordPress Version: 6.2

/**
 * Retrieves an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$post` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $post      Optional. Post ID or post object.
 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($post = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($post);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters the list of attachment link attributes.
     *
     * @since 6.2.0
     *
     * @param array $attributes An array of attributes for the link markup,
     *                          keyed on the attribute name.
     * @param int   $id         Post ID.
     */
    $attributes = apply_filters('wp_get_attachment_link_attributes', array('href' => $url), $_post->ID);
    $link_attributes = '';
    foreach ($attributes as $name => $value) {
        $value = ('href' === $name) ? esc_url($value) : esc_attr($value);
        $link_attributes .= ' ' . esc_attr($name) . "='" . $value . "'";
    }
    $link_html = "<a{$link_attributes}>{$link_text}</a>";
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the `$attr` parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int|WP_Post  $post      Post ID or object. Can be 0 for the current global post.
     * @param string|int[] $size      Requested image size. Can be any registered image size name, or
     *                                an array of width and height values in pixels (in that order).
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon.
     * @param string|false $text      If string, will be link text.
     * @param array|string $attr      Array or string of attributes.
     */
    return apply_filters('wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 6.1

/**
 * Retrieves an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$post` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $post      Optional. Post ID or post object.
 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($post = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($post);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    $link_html = "<a href='" . esc_url($url) . "'>{$link_text}</a>";
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the `$attr` parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int|WP_Post  $post      Post ID or object. Can be 0 for the current global post.
     * @param string|int[] $size      Requested image size. Can be any registered image size name, or
     *                                an array of width and height values in pixels (in that order).
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon.
     * @param string|false $text      If string, will be link text.
     * @param array|string $attr      Array or string of attributes.
     */
    return apply_filters('wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.9

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the `$attr` parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int|WP_Post  $id        Post ID or object. Can be 0 for the current global post.
     * @param string|int[] $size      Requested image size. Can be any registered image size name, or
     *                                an array of width and height values in pixels (in that order).
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon.
     * @param string|false $text      If string, will be link text.
     * @param array|string $attr      Array or string of attributes.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.8

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the `$attr` parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|int[] $size      Requested image size. Can be any registered image size name, or
     *                                an array of width and height values in pixels (in that order).
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon.
     * @param string|false $text      If string, will be link text.
     * @param array|string $attr      Array or string of attributes.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.7

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the $attr parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|int[] $size      Requested image size. Can be any registered image size name, or
     *                                an array of width and height values in pixels (in that order).
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon.
     * @param string|false $text      If string, will be link text.
     * @param array|string $attr      Array or string of attributes.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.6

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the $attr parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|int[] $size      Requested image size. Can be any registered image size name, or
     *                                an array of width and height values in pixels (in that order).
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon.
     * @param string|bool  $text      If string, will be link text.
     * @param array|string $attr      Array or string of attributes.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.5

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' !== $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the $attr parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     * @param array|string $attr      Array or string of attributes. Default empty.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    $url = wp_get_attachment_url($_post->ID);
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the $attr parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     * @param array|string $attr      Array or string of attributes. Default empty.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 5.1

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     * @since 5.1.0 Added the $attr parameter.
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     * @param array|string $attr      Array or string of attributes. Default empty.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text, $attr);
}

WordPress Version: 4.7

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' !== $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if ('' === trim($link_text)) {
        $link_text = $_post->post_title;
    }
    if ('' === trim($link_text)) {
        $link_text = esc_html(pathinfo(get_attached_file($_post->ID), PATHINFO_FILENAME));
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.6

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filters a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 5.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .10

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.5

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .10

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
 *                                of width and height values in pixels (in that order).
 *                                Default 'thumbnail'.
 * @param bool         $permalink Optional, Whether to add permalink to image. Default false.
 * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
 * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
 *                                Default false.
 * @param array|string $attr      Optional. Array or string of attributes. Default empty.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string       $link_html The page link HTML output.
     * @param int          $id        Post ID.
     * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
     *                                Default 'thumbnail'.
     * @param bool         $permalink Whether to add permalink to image. Default false.
     * @param bool         $icon      Whether to include an icon. Default false.
     * @param string|bool  $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 3.5

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 3.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 3.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 3.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .10

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 2.9

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 2.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 2.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 2.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .10

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 1.5

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .40

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 1.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 1.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 1.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .12

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.1

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 *
 * @param int|WP_Post  $id        Optional. Post ID or post object.
 * @param string       $size      Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool         $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool         $icon      Optional, default is false. Whether to include icon.
 * @param string|bool  $text      Optional, default is false. If string, then will be link text.
 * @param array|string $attr      Optional. Array or string of attributes.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '')
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon, $attr);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 0.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 0.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 0.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .12

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 4.0

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 9.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .13

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 3.9

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int|WP_Post $id Optional. Post ID or post object.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    /**
     * Filter a retrieved attachment page link.
     *
     * @since 2.7.0
     *
     * @param string      $link_html The page link HTML output.
     * @param int         $id        Post ID.
     * @param string      $size      Image size. Default 'thumbnail'.
     * @param bool        $permalink Whether to add permalink to image. Default false.
     * @param bool        $icon      Whether to include an icon. Default false.
     * @param string|bool $text      If string, will be link text. Default false.
     */
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 8.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 8.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 8.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .15

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 7.5

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .40

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 7.4

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .30

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 7.3

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .20

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 7.2

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: .15

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='" . esc_url($url) . "'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}

WordPress Version: 3.7

/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string|bool $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post = get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !$url = wp_get_attachment_url($_post->ID)) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = $text;
    } elseif ($size && 'none' != $size) {
        $link_text = wp_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('wp_get_attachment_link', "<a href='{$url}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}