Skip to content

Instantly share code, notes, and snippets.

@cdils
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdils/4e6a67b268ce6c5e36ff to your computer and use it in GitHub Desktop.
Save cdils/4e6a67b268ce6c5e36ff to your computer and use it in GitHub Desktop.
Two methods to add post author avatar to entry header
<?php // remove this line
/**
* Add author avatar to post info output
*
* @uses get_avatar() <http://codex.wordpress.org/Function_Reference/get_avatar>
* @uses get_author_posts_url() <http://codex.wordpress.org/Function_Reference/get_author_posts_url>
*/
add_filter( 'genesis_post_info', 'cd_post_info_filter' );
function cd_post_info_filter( $post_info ) {
// get author details
$entry_author = get_avatar( get_the_author_meta( 'email' ), 64 );
$author_link = get_author_posts_url( get_the_author_meta( 'ID' ) );
// build updated post_info
$post_info = sprintf( '<span class="author-avatar"><a href="%s">%s</a></span>', $author_link, $entry_author );
$post_info .= '[post_date] by [post_author_posts_link] [post_comments] [post_edit]';
return $post_info;
}
<?php // remove this line
/**
* Hook author avatar by post title on single post
*
* @uses get_avatar() <http://codex.wordpress.org/Function_Reference/get_avatar>
* @uses get_author_posts_url() <http://codex.wordpress.org/Function_Reference/get_author_posts_url>
*/
add_action( 'genesis_entry_header', 'cd_author_gravatar' );
function cd_author_gravatar() {
if ( is_singular( 'post' ) ) {
$entry_author = get_avatar( get_the_author_meta( 'email' ), 64 );
$author_link = get_author_posts_url( get_the_author_meta( 'ID' ) );
printf( '<div class="author-avatar"><a href="%s">%s</a></div>', $author_link, $entry_author );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment