Wordpress display post Author photo image url

Asked

Viewed 234 times

0

Anyone here knows how to tell me how to get the image url of the photo from Author or post administrator in wordpress ?

1 answer

1


The author’s photo is also called avatar.

To show the avatar inside the loop of Wordpress is like this:

<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>

The first parameter is email, user/author id or a post object. The second parameter is optional and represents the size of the image with the maximum being 512 and the default being 96.

If you prefer only the image url use the function get_avatar_url. The first parameter is similar to get_avatar. The second parameter is an array and accepts several value keys being size to the size.

Example:

<?php echo get_avatar_url( get_the_author_meta( 'ID' ), ['size' => 32] ); ?>

For more examples see in the official documentation of the functions. https://codex.wordpress.org/Function_Reference/get_avatar https://developer.wordpress.org/reference/functions/get_avatar_url/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.