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 '
'.$i.'
'; } else { return ''; } } } function caption_image($post_body_content) { $post_body_content = preg_replace_callback("||","caption_image_callback",$post_body_content); return $post_body_content; } if ( current_user_can('edit_plugins') ) { add_filter('the_content', 'caption_image'); }