First off, I want to say thank you for taking the time to even read this, I really do appreciate the help this site and it’s community has given me thus far.
i have looked forever to be able to find a way to append (display inside an added div) some image meta data just below EVERY image in EVERY single post. I have found some stuff for NextGen Gallery and some other things, but that is way too much bloat, I just want to attach a div and a couple spans, with a little php thrown in there!
I am building a fairly huge magazine style website, and a lot of the images will need to be accredited to photographers who don’t directly work for the site.
I have been searching for a way to do this via php, not js. I like the plugin Media Custom Fields it lets me add a couple extra lines of meta to every media file, which is perfect. I don’t need any help with pulling that meta out and displaying it once I know how to append something to every image.
Meaning that, after someone can help me find out how to add stuff to all the images, i should be able to take it from there!
I know that this code does not work or make sense, but maybe some of you can figure out exactly what I need from this example, I hope! :
add_filter('image', 'add_stuff',);
function add_stuff($image_meta)
{
$image_meta = '';
$author_name = get_post_meta($post->ID, "tamcf_author_name", TRUE );
$author_website = get_post_meta($post->ID, "tamcf_author_website", TRUE);
if (is_single() && (is_image())
{
foreach( $images as $image )
{
$image_meta .= '<div class="extra_image_meta"><span>' . $author_name . '</span><span>' . $author_website . '</span></div>';
}
}
$image .= $image_meta
return $image
}
That is pretty much what I need to happen, if you all can understand that!
UPDATE
I did not test this method, but it is not very old. It adds custom meta information to the caption section of the image, which can then be styled as needed. Again, I did not try the method, and I am not a coder, but from reading through the tutorial, it sounds like it fits your needs.
Add Custom Meta Fields to Media Attachments in WordPress
Original Answer
I think this article from wpbeginner might be exactly what you need. I have used this exact method before.
How to Add Additional Fields to the WordPress Media Uploader