post_avatars

This shortcode allows you to show the avatars of all the authors of a post.

It can be used anywhere within WordPress where shortcodes are supported. For most users, this will primarily be within the content of a WordPress post or page or the sidebar.

The output can be customized making use of the optional attributes this shortcode can take.

Examples

Single Author Post

The trivial shortcode would look like:

Editor input

[post_avatars]

Frontend output

As you can see, you get the profile image of the only author of a post. If you don’t provide any post ID, current post is taken by default.

Multi-Author Post

Again, using the trivial shortcode:

Editor input

[post_avatars]

Frontend output

 

That would show your current post author’s avatars, making them link to each author page

More Examples

Custom Image Size

Let’s say you want to display images with a size of 50×50 pixels. Then you should make use of the size attribute like this:

Editor input

[post_avatars size=’50,50′]

Frontend output

author_avatar
author_avatar_2

Avatars Without Link

In this examples images are not links. But default shortcode’s output will make author images to link to their author pages. So let’s imagine now that you want to disable those links. In that case, you should input the shortcode with the linkattribute:

Editor input

[post_avatars link=no]

Custom Styles

You probably may want to customize how avatars are displayed. The HTML markup that shortcode generates by default look like this:

				
					
<div class="m-post-avatars">
    <div class="m-post-avatar">
        <img decoding="async" src="">
    </div>
    <div class="m-post-avatar">
        <img decoding="async" src="">
    </div>
    ...
</div>
				
			

Those classes has no CSS rules defined, so you can use them to provide your own.

Or you can even change the DOM element tag to use and the class they must have:

Editor input

[post_avatars container_tag=section container_id=myId container_class=myClass wrapper_class=myClass2]

Frontend output

				
					
<section id="myId" class="m-post-avatars myClass">
    <div class="m-post-avatar myClass2">
        <img decoding="async" src="">
    </div>
    <div class="m-post-avatar myClass2">
        <img decoding="async" src="">
    </div>
    ...
</section>
				
			

Attributes

Check out below all the available attributes this shortcode can take:

pidoptional
Post ID. If none provided, current post ID is taken.
Accepts integer as post ID.
Defaults to current post ID.
Available since version 1.2.0.
sizeoptional
Avatar size.
Accepts Any defined image size in your WP: (thumbnail, medium, medium_large, large, full…) or a custom value (x,y).
Defaults to full.
Available since version 1.2.0.
contextoptional
Set to ‘box’ to take defined styles for the author avatar displayed in author boxes
Accepts “screen” or “box”.
Defaults to screen.
Available since version 1.2.0.
sourceoptional
Where to retrieve the avatar from
Accepts “local”, “gravatar” or “acronym”.
Defaults to local.
Available since version 1.2.0.
defaultoptional
Default image to load if none is found in the provided source
Accepts “gravatar”, “acronym”, “mp”, “blank”, “none”.
Defaults to gravatar.
Available since version 1.2.0.
linkoptional
Whether to make avatars link to their author page
Accepts “yes” or “no”.
Defaults to yes.
Available since version 1.2.0.
link_classoptional
CSS class name to add to the link element
Available since version 1.2.0.
wrapper_tagoptional
HTML tag used to enclose each image markup
Available since version 1.2.0.
wrapper_classoptional
CSS class name to add to each image wrapper
Available since version 1.2.0.
container_tagoptional
HTML tag used to enclose all images markup
Available since version 1.2.0.
container_idoptional
ID to add to the avatars container
Available since version 1.2.0.
container_classoptional
CSS class name to add to the avatars container
Available since version 1.2.0.
display_errorsoptional
Whether to display a message in case of error
Accepts “yes” or “no”.
Defaults to yes.
Available since version 1.2.0.
Updated on February 26, 2022

Did not find a solution? We are here to help you succeed.
Open a support ticket