Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show author avatar in entry header of feature post only, not teasers - in Genesis - support for Co-Authors Plus
<?php
/**
* Places the author avatar next to the entry header for feature posts, not teaser posts.
* Includes support for co-authors plus plugin
* Replace the BLOGLOGURL with an actual url to an alternate image
*
* @author Joshua David Nelson, joshuadnelson.com
**/
add_action( 'genesis_entry_header', 'jdn_author_post_avatar', 1 ); // using a priority of 1 to insure it is first, before title
function jdn_author_post_avatar() {
if( is_home() || is_single() ){ // only on blog page and single post pages, not on archives
if( in_array( 'feature', get_post_class( '', get_the_ID() ), true ) || is_single() ) { // only on posts with a 'feature' class
if( !function_exists( 'get_coauthors' ) || ( function_exists( 'get_coauthors' ) && 1 == count( get_coauthors( get_the_id() ) ) ) ) { // if using co-authors and a single author, or if not using co-authors
if( get_query_var( 'author_name' ) ) {
$curauth = get_userdatabylogin( get_query_var( 'author_name' ) );
} else {
$curauth = get_userdata( get_query_var( 'author' ) );
}
?>
<div class="author_grav">
<? echo "<a href=\"/author/" . get_the_author_meta( 'user_login' ) . "\">" . get_avatar( get_the_author_meta( 'email' ), '50' ) . "</a>"; ?>
</div>
<?php
} else { // otherwise, let's use the blog logo
?>
<div class="author_grav">
<a href="/members/"><img src="BLOGLOGOURL" width="50" height="50" class="avatar" /></a>
</div>
<?php
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.