Last active
September 29, 2018 06:03
-
-
Save carasmo/db69d9497119c0bea4c340c6d72601f7 to your computer and use it in GitHub Desktop.
Get Gravatar / Avatar Outside of loop WordPress.
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 | |
//* Do not copy above. Add the hook where it's going. Change the function name to reflect your situation. | |
add_action( 'your_hook', 'themeprefix_author_gravatar_outside_loop_single_post' ); | |
//* Author Gravatar/Avatar outside of Loop on Single posts | |
function themeprefix_author_gravatar_outside_loop_single_post() { | |
if ( is_single() ) : | |
global $post; | |
$author_id = $post->post_author; | |
$author_link = esc_url( get_author_posts_url( get_the_author_meta( $author_id ) ) ); | |
$author_avatar = get_avatar( $author_id, 200 ); | |
printf( '<a href="%s">%s</a>', $author_link, $author_avatar ); | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment