the_attachment_link() WordPress Function

The attachment link function is used to get the URL for an attachment. It can be used with images, videos, and other types of attachments.

the_attachment_link( int|WP_Post $id, bool $fullsize = false, bool $deprecated = false, bool $permalink = false ) #

Displays an attachment page link using an image or icon.


Parameters

$id

(int|WP_Post)(Optional) Post ID or post object.

$fullsize

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

Default value: false

$deprecated

(bool)(Optional)Deprecated. Not used.

Default value: false

$permalink

(bool)(Optional) Whether to include permalink.

Default value: false


Top ↑

More Information

Outputs an HTML hyperlink to an attachment file or page, containing either

  1. A full-size image or thumbnail for image attachments; or
  2. The attachment’s title (as text) for non-image attachments

If no attachment can be found, the function displays the string Missing Attachment.

Use wp_get_attachment_link() instead if you just want to get the hyperlink, not print it.


Top ↑

Source

File: wp-includes/post-template.php

function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '2.5.0' );
	}

	if ( $fullsize ) {
		echo wp_get_attachment_link( $id, 'full', $permalink );
	} else {
		echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
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.