Warning: This function has been deprecated. Use wp_get_attachment_link() instead.

get_the_attachment_link() WordPress Function

The get_the_attachment_link() function retrieves the URL for an attachment. This function is useful for displaying links to attachments in the front-end. For example, you could use this function to display a list of attachments for a post.

get_the_attachment_link( int $id, bool $fullsize = false, array $max_dims = false, bool $permalink = false ) #

Retrieve HTML content of attachment image with link.


Description

Top ↑

See also


Top ↑

Parameters

$id

(int)(Optional) Post ID.

$fullsize

(bool)(Optional) Whether to use full size image.

Default value: false

$max_dims

(array)(Optional) Max image dimensions.

Default value: false

$permalink

(bool)(Optional) Whether to include permalink to image.

Default value: false


Top ↑

Return

(string)


Top ↑

Source

File: wp-includes/deprecated.php

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>";
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Use wp_get_attachment_link()
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More