I need to get the post author profile picture link.
I know I can use get_avatar();
but it displays whole image markup
<img src="http://.../img.png" class="avatar img-responsive" alt="image">
But need only the src
of the author profile pic.
How can I got that ? Maybe we can use some php
or js
to take out the only src
value from the total output.
My second question is, how can I add that image
as post_thumbnail
if no thumbnail exist for that post ?
5 Answers
Putting the following inside loop should fulfill your needs:
<?php
$get_author_id = get_the_author_meta('ID');
$get_author_gravatar = get_avatar_url($get_author_id, array('size' => 450));
if(has_post_thumbnail()){
the_post_thumbnail();
} else {
echo '<img src="'.$get_author_gravatar.'" alt="'.get_the_title().'" />';
}
?>