Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Filter to get caption and append image information to it.
- *
- * @returns text HTML content describing with media attribution
- **/
- add_filter('get_image_tag', 'append_media_credit', 10, 2);
- function append_media_credit($html, $id) {
- $media_string = media_credit_string( $id );
- $html = $html . $media_string;
- return $html;
- }
- /**
- * Function to lookup media creator fields and put them together.
- *
- * @returns an html string with creator name and license name links.
- **/
- function media_credit_string( $media_id ) {
- $name = get_post_meta( $media_id, 'creator_name', true );
- $name_url = get_post_meta( $media_id, 'creator_url', true );
- $license_name = get_post_meta( $media_id, 'license_name', true );
- $license_url = get_post_meta( $media_id, 'license_url', true );
- $creator = null;
- if( $name ) {
- if( $name_url ) {
- $creator = ' <a href="' . $name_url . '">' . $name . '</a>.';
- } else {
- $creator = ' ' . $name;
- }
- }
- $license = null;
- if( $license_name ) {
- if( $license_url ) {
- $license = ' <a href="' . $license_url . '">' . $license_name . '</a>.';
- } else {
- $license = ' ' . $license_name;
- }
- }
- return '<span class="mrw-media-attr">Credit:' . $creator . $license . '</span>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement