WordPress V3.0+Template Tag Reference Guide
Presented by:
Attachment Tags
Get Attachment Link get_attachment_link();
Returns the URI of the page for an attachment.
<?php get_attachment_link(id); ?>
id
Type: Integer
The ID of the attachment.
Is Attachment is_attachment();
This Conditional Tag checks if an attachment is being displayed. An attachment is an image or other file uploaded through the post editor's upload utility. Attachments can be displayed on their own 'page' or template. For more information, see Using Image and File Attachments. This is a boolean function, meaning it returns either True or False.
<?php is_attachment(); ?>
No parameters.
The Attachment Link the_attachment_link();
Outputs a hyperlink to the attachment file, or Missing Attachment if the attachment can't be found. The hyperlink contains either (1) a thumbnail or full-size image (as specified), if it exists; or (2) an icon representing the media type of the file, if it exists; or (3) the attachment title (as text).
<?php the_attachment_link(id, fullsize, permalink); ?>
id
Type: Integer
ID of the desired attachment. Optional; defaults to the ID of the current post.
fullsize
Type: Boolean · Default: False
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.
permalink
Type: Boolean · Default: False
Link to the attachment page (true) or directly to the file/image (false).
Attachment Is Image wp_attachment_is_image();
This function determines if a post's attachment is an image. It returns True if the attachment is an image, False if not.
<?php wp_attachment_is_image($post_id); ?>
&post_id
Type: Integer
Integer ID of the post.
Get Attachment Image wp_get_attachment_image();
Returns an HTML image element representing an attachment file, if there is any, otherwise an empty string.
<?php echo wp_get_attachment_image($attachment_id, $size, $icon); ?>
$attachment_id
Type: Integer
ID of the desired attachment. Usually required; you can omit it inside a Loop of attachments (such as on an attachment page).
$size
Type: String | Array · Default: Thumbnail
Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size. Optional.
$icon
Type: Boolean · Default: False
Use a media icon to represent the attachment. Optional.
Get Attachment Image Sourcewp_get_attachment_image_src();
Returns an image representing an attachment file, if there is any. Else returns False.
<?php wp_get_attachment_image_src($attachment_id, $size, $icon); ?>
$attachment_id
Type: Integer
ID of the desired attachment.
$size
Type: String | Array · Default: Thumbnail
Size of the image shown for an image attachment: either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32). As of Version 2.5, this parameter does not affect the size of media icons, which are always shown at their original size. Optional.
$icon
Type: Boolean · Default: False
Use a media icon to represent the attachment. Optional.
Get Attachment MetaDatawp_get_attachment_metadata();
Retrieve attachment meta field for attachment ID. Returns False on failure.
<?php wp_get_attachment_metadata($post_id, $unfiltered) ?>
$post_id
Type: Integer
(Required) ID of the desired attachment.
$unfiltered
Type: Boolean | Array · Default: False
If true, filters are not run.