Last active
August 29, 2015 14:02
-
-
Save iamcanadian1973/32c57bcc28b112a8b62e to your computer and use it in GitHub Desktop.
Get image attachment (title, alt, caption, url, width, height)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get image attachment (title, alt, caption, url, width, height) | |
* | |
*/ | |
// get attachment ID if featured image | |
$attachment_id = get_post_thumbnail_id( $post->ID ); | |
// best function ever - http://codex.wordpress.org/Function_Reference/wp_prepare_attachment_for_js | |
$image = wp_prepare_attachment_for_js($attachment_id); | |
// if using a custom image size then make sure it exists if not default to "full" | |
$size = isset($image['sizes']['custom-size']) ? 'custom-size' : 'full'; | |
$title = $image['title']; | |
$alt = $image_atr['alt']; | |
$caption = $image_atr['caption']; | |
$url = $image['sizes'][$size]['url']; | |
$width = $image['sizes'][$size]['width']; | |
$height = $image['sizes'][$size]['height']; | |
// print out the image | |
if ($image) printf('<img src="%s" alt="%s" width="%s" height="%s" />', $url, $alt, $width, $height); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
groovy, this is terrific - $image_atr should be $image tho