On this page
get_the_attachment_link( int $id, bool $fullsize = false, array $max_dims = false, bool $permalink = false ): string
This function has been deprecated. Use wp_get_attachment_link() instead.
Retrieve HTML content of attachment image with link.
Description
See also
Parameters
$idint Optional-
Post ID.
$fullsizebool Optional-
Whether to use full size image.
Default:
false $max_dimsarray Optional-
Max image dimensions.
Default:
false $permalinkbool Optional-
Whether to include permalink to image.
Default:
false
Return
string
Source
File: wp-includes/deprecated.php. View all references
function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {
_deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_link()' );
$id = (int) $id;
$_post = get_post($id);
if ( ('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);
$innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
return "<a href='$url' title='$post_title'>$innerHTML</a>";
}
Related
Uses
| Uses | Description |
|---|---|
| get_attachment_innerHTML() wp-includes/deprecated.php | Retrieve HTML content of image element. |
| get_attachment_link() wp-includes/link-template.php | Retrieves the permalink for an attachment. |
| wp_get_attachment_url() wp-includes/post.php | Retrieves the URL for an attachment. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| _deprecated_function() wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Use wp_get_attachment_link() |
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_attachment_link