Joshua David Nelson

Bullshit Free WordPress Development

  • Services
  • Code
  • About
  • Contact

Post Avatars in Entry Header in Genesis

This places the post avatar in the entry header of feature posts (if you're using the grid loop plugin) and on single post pages. It also allows for co-author plus support, showing a different image when there is more than one author.

<?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
}
}
}
}
view raw author-avatar-in-post-header.php hosted with ❤ by GitHub

Source: https://gist.github.com/joshuadavidnelson/9065384

Tags: avatar, co-author plus, Genesis, grid loop

Previous Code:
Exclude Scripts from Scripts-to-Footer Plugin
Back to the Code Snippets
Next Code:
Specific Page Sidebar with Genesis
  • Twitter
  • RSS Feed URL

About Me

I'm a WordPress Engineer. I build sleek, custom websites with WordPress and Genesis.

See my services and my recent work.

Contact me to get your project started.

Gravity Forms Plugin for WordPress Fastest WordPress Hosting

Recent Posts

  • Using Font Awesome Icons for WooCommerce Grid / List Toggle
  • Disable Blog: WordPress Gone Blog-less
  • Category (Taxonomy) Dropdown Filtered By Post Type
  • Weather in WordPress with Dark Sky
  • Fixing Your Deprecated Widget Constructors in WordPress 4.3
  • Twitter
  • RSS Feed URL
  • Code Snippets
  • My Plugins
  • Make a Payment

© Joshua David Nelson | Hand-Forged | WordPress + Genesis | Terms of Service | Legal | Contact