WordPress V4.0+Template Tag Reference Guide as of Version 4.2
Presented by DBS > Interactive Development :
Attachment Tags
Get Attachment Link get_attachment_link();
Returns the URI of the page for an attachment.
<?php get_attachment_link($id); ?>
$id
Integer • Default: The current post ID, when used in The Loop.
(Optional) The numeric 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
Integer • Default: the ID of the current post
(Optional) ID of the desired attachment.
$fullsize
Boolean • Default: false
(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.
$permalink
Boolean • Default: false
(Optional) Link to the attachment page (true) or directly to the file/image (false).
WP 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
Integer • Default: 0
Integer ID of the post.
WP 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
Integer • Default: none
ID of the desired attachment.
$size
String/Array • Default: 'thumbnail'
(Optional) 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.
$icon
Boolean • Default: false
(Optional) Use a media icon to represent the attachment.
WP 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
Integer • Default: none
ID of the desired attachment.
$size
String/Array • Default: 'thumbnail'
(Optional) 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.
$icon
Boolean • Default: false
(Optional) Use a media icon to represent the attachment.
WP Get Attachment Linkwp_get_attachment_link();
Returns an image representing an attachment file, if there is any. Else returns False.
<?php wp_get_attachment_link($id, $size, $permalink, $icon, $text); ?>
$id
Integer • Default: The current post ID, when used in a loop showing only attachments
ID of the desired attachment.
$size
String/Array • Default: 'thumbnail'
(Optional) 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.
$permalink
Boolean • Default: false
(Optional) Link directly to the attachment file/image (Default), or to the attachment page.
$icon
Boolean • Default: false
(Optional) Use a media icon to represent the attachment.
$text
String • Default false
(Optional) Displays a text link to the attachment.
WP 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
Integer • Default: none
ID of the desired attachment.
$unfiltered
Boolean/Array • Default: false
(Optional) If true, filters are not run.