Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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
    Enrico

    #1007260

    Hey enricobaumgart,

    You want to display this info on the front end?

    Best regards,
    Jordan Shannon

    #1007279

    Yes right, I wanna add a shortcode below a featured picture in the blog and show the copyright information.
    Best regards, Enrico

    #1007281

    Hi,

    Please refer to the following:

    https://kriesi.at/support/topic/copyright-option-for-images/

    Best regards,
    Jordan Shannon

    #1007294

    Thanks 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

    #1007922

    Hi,

    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,
    Peter

    #1008609

    Hello 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

    #1008779

    Hi,

    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, 2 months ago by Dude.
    #1009069

    Hello Peter,
    That works perfect. Many thanks for your support!
    Best regards
    Enrico

    #1009076

    Hi!

    Great, glad I could help you :)

    Best regards,
    Peter

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.