Ready to get started?Download WordPress


Function Reference/the attachment link



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.


<?php the_attachment_link$id$fullsize$deprecated$permalink ); ?>

Default Usage

<?php the_attachment_link( 7 ); ?>


(integer) (Optional) ID of the desired attachment.
Default: The current post ID, when used in The Loop (Must be a loop showing only attachments).
(boolean) (Optional) 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.
Default: 'False'
(array) (Deprecated parameter since Version 2.3) 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
Default: not used
(boolean) (Optional) Link directly to the attachment file/image (Default), or to the attachment page.
Default: 'False'



// Show an image at full size linked to the attachment file
the_attachment_link( 4, true );

// Show a thumbnail linked to the attachment page
the_attachment_link( 4, false, false, true );



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

Change Log

Since: 2.0.0

Source File

the_attachment_link() is located in wp-includes/post-template.php.


Attachment Functions: the_attachment_link(), get_attachment_link(), wp_get_attachment_link(), wp_get_attachment_image(), wp_get_attachment_image_src(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_thumb_url(), is_attachment(), wp_get_attachment_metadata()