I tried to do this once and almost got almost. Here’s what I did learn. Depending on your needs, this solution may be workable.
You can append content to media when it’s inserted into the editor using the get_image_tag
filter:
/**
* Filter to get caption and append image information to it.
*
* @return text HTML content describing with media attribution
**/
add_filter('get_image_tag', 'my_append_media_credit', 20, 2);
function my_append_media_credit( $html, $id ) {
$my_media_string = /* get your fields and put them together nicely */;
$html = $html . $my_media_string;
return $html;
}
However, you’ll notice that I mentioned it only works for images when they’re inserted into posts (and possibly updated, though I’d need to check out that). So if you’re starting a site from scratch, that may get you far enough, but I got stuck on retroactively applying it to existing images in posts.
You could get some additional coverage for images with captions by filtering img_caption_shortcode
which filters the shortcode output but that still leaves images without captions and already in posts uncovered.
UPDATE 10/23/13 2:20pm PST:
Here’s the function I used to generate the $my_media_string
in the code above:
/**
* Function to lookup media creator fields and put them together.
*
* returns an html string with creator name and license name links.
**/
function my_media_credit_string( $my_media_id ) {
$my_name = get_post_meta( $my_media_id, 'my_creator_name', true );
$my_name_url = get_post_meta( $my_media_id, 'my_creator_url', true );
$my_creator = null;
if( $my_name ) {
if( $my_name_url ) {
$my_creator=" <a href="" . $my_name_url . '">' . $my_name . '</a>.';
} else {
$my_creator=" " . $my_name;
}
}
return '<span class="my-media-attr">Credit:' . $my_creator . '</span>';
}
So the first snippet would get this:
$my_media_string = $my_media_credit_string( $id );