Last active
August 29, 2015 14:01
-
-
Save scofennell/f1f4a658a419ef5f6c5a to your computer and use it in GitHub Desktop.
WordPress function to return the name of the photographer of a photo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Returns the name of the photographer for the current post, along with a Font Awesome icon. | |
| * | |
| * @return string The name of the photographer for the current post, along with a Font Awesome icon. | |
| */ | |
| function sjf_deh_get_photo_creds() { | |
| // get the current post | |
| $post = get_post(); | |
| // if this is not an attachment post, bail | |
| if (empty ( $post->post_type ) || ( $post->post_type != 'attachment' ) ) { return false; } | |
| // Get the term from the 'photographer' taxonomy | |
| $photog = wp_get_post_terms( $post->ID, 'photographer' ); | |
| // if this post has not been tagged with any photographers, bail | |
| if( !$photog ) { return false; } | |
| // we just want the first photographer | |
| $p = $photog[0]; | |
| // get the term name | |
| $out = esc_html( $p->name ); | |
| // the icon refers to FontAwesome | |
| $out="<div class='photog'><i class='icon-camera'></i> $out</div>"; | |
| return $out; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment