Template Tags/the attachment link
Outputs a hyperlink to the attachment file, or Missing Attachment if the attachment can't be found.
The hyperlink contains either
- A thumbnail or full-size image (as specified), if it exists; or
- An icon representing the media type of the file, if it exists; or
- The attachment title (as text)
Since Version 2.5, the attachment link() seems to be deprecated in favor of wp_get_attachment_link().
Example usage
<?php
// Default
the_attachment_link(7);
// Show an image or icon at no more than 48 x 48 pixels
the_attachment_link( 13, false, array(48, 48) );
// Show an image at full size (also linked to the file)
the_attachment_link( 4, true );
?>
Parameters
- id
- (integer) ID of the desired attachment. Optional; defaults to the ID of the current post.
- fullsize
- (boolean) For an image attachment, use the original image (true) or Wordpress-generated thumbnail (false). If set to false and the thumbnail can't be found, the full-size image may be used instead. Optional; default false
- max_dims (deprecated since Version 2.3)
- (array) Maximum width and height of the image or icon, applied to the width and height attributes of the image element (img) output by the function. The aspect ratio is kept constant. Optional.
- permalink
- Link to the attachment page (true) or directly to the file/image (false; default).
Related
Use get_the_attachment_link(id) instead if you just want to get the hyperlink, not print it.