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

Displays an attachment page link using an image or icon.

Parameters

$postint|WP_Postoptional
Post ID or post object.
$fullsizebooloptional
Whether to use full size.

Default:false

$deprecatedbooloptional
Deprecated. Not used.

Default:false

$permalinkbooloptional
Whether to include permalink.

Default:false

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.

Source

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

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

Changelog

VersionDescription
2.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.