Skip to content

Instantly share code, notes, and snippets.

@scofennell
Last active August 29, 2015 14:01
Show Gist options
  • Save scofennell/f1f4a658a419ef5f6c5a to your computer and use it in GitHub Desktop.
Save scofennell/f1f4a658a419ef5f6c5a to your computer and use it in GitHub Desktop.
WordPress function to return the name of the photographer of a photo.
<?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