-
AuthorPosts
-
September 7, 2018 at 6:29 pm #1007247
Hello,
Does anybody knows an option to get the meta data of an image via a shortcode?
I want to get the copyright information, which I filled in after uploading the image.
So I only wanna get a specific information, not all the meta data. I know there is a plugin called “Image Source Control”, but this doesn’t help.Thanks & best regards
EnricoSeptember 7, 2018 at 7:15 pm #1007260Hey enricobaumgart,
You want to display this info on the front end?
Best regards,
Jordan ShannonSeptember 7, 2018 at 7:47 pm #1007279Yes right, I wanna add a shortcode below a featured picture in the blog and show the copyright information.
Best regards, EnricoSeptember 7, 2018 at 7:52 pm #1007281Hi,
Please refer to the following:
https://kriesi.at/support/topic/copyright-option-for-images/
Best regards,
Jordan ShannonSeptember 7, 2018 at 8:28 pm #1007294Thanks Jordan,
But this doesn’t help me, because it’s not working for the featured images on the blog posts, but only for gallery images, or did I miss something?Thanks, Enrico
September 10, 2018 at 2:00 pm #1007922Hi,
Please add this code to your child theme:
function avia_display_image_copyright( $atts ) { $atts = shortcode_atts(array('id' => ''), $atts); $copyright_text = ''; if(!empty($atts['id'])) { $copyright_text = get_post_meta($atts['id'], '_avia_attachment_copyright', true ); } else { if(has_post_thumbnail()) { $post_thumbnail_id = get_post_thumbnail_id(); $copyright_text = get_post_meta($post_thumbnail_id, '_avia_attachment_copyright', true ); } } return $copyright_text; } add_shortcode( 'av_display_image_copyright', 'avia_display_image_copyright' );
You can then use this shortcode:
[av_display_image_copyright]
to display the copyright information of the featured image. If you want to display the copyright information of another image (which is not the featured image) you can use this code:
[av_display_image_copyright id=852]
and replace 852 with the (attachment) id of the image.
Best regards,
PeterSeptember 11, 2018 at 9:01 pm #1008609Hello Peter,
Thats works nice already!
Is it also possible to get a CSS class to that copyright information? Right now I get the following html code:<p style="">Leo Rivas / fotolia<br></p>
Can I add any custom class on the p-element?
Thanks a lot, Enrico
September 12, 2018 at 8:03 am #1008779Hi,
Sure – you can replace i.e. the line:
return $copyright_text;
with
if(!empty($copyright_text)) $copyright_text = '<div class="avia_image_copyright">'.$copyright_text.'</div>'; return $copyright_text;
and then use the avia_image_copyright class to style the copyright text.
Best regards,
Peter- This reply was modified 6 years, 3 months ago by Dude.
September 12, 2018 at 9:04 pm #1009069Hello Peter,
That works perfect. Many thanks for your support!
Best regards
EnricoSeptember 12, 2018 at 9:41 pm #1009076Hi!
Great, glad I could help you :)
Best regards,
Peter -
AuthorPosts
- You must be logged in to reply to this topic.