function count_images(){ global $post; $thePostID = $post->ID; $parameters = array( 'post_type' => 'attachment', 'post_parent' => $thePostID, 'post_mime_type' => 'image'); $attachments = get_children($parameters); $content = count($attachments); return $content; } #add_filter('the_content','count_images'); function caption_image_callback($matches) { $c = count_images(); for ($i=1; $i <= $c; $i++) { if (is_single()) { return '