How to extract the caption of an image
-
I’ve been looking for a way to extract the caption of an image to place it wherever I want but I couldn’t find anything in the Codex, or a shorttag for it, so it had to be a custom function.
So, to get the caption of your last added image (even if it is a thumbnail in WP 2.9+) use this code inside the loop:
<?php
if ($images =& get_children('post_type=attachment&post_parent='.$post->ID))
{
foreach($images as $image)
{
$caption = $image->post_excerpt;
$description = $image->post_content;
echo $caption;
}
}
?>Wrap it in a div and place it wherever you want inside your post (well usually below the image ??
- The topic ‘How to extract the caption of an image’ is closed to new replies.