WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/the attachment link

Description

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.

Usage

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

Default Usage

<?php the_attachment_link( 7 ); ?>

Parameters

$id
(integer) (Optional) ID of the desired attachment.
Default: The current post ID, when used in The Loop (Must be a loop showing only attachments).
$fullsize
(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'
$max_dims
(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
$permalink
(boolean) (Optional) Link directly to the attachment file/image (Default), or to the attachment page.
Default: 'False'

Examples

<?php

// 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 );

?>

Notes

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.

Related

Attachment Functions:

get_children(), get attached media(), 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()