Post Author action is used to display information about the post author.
This action can only be used together with Show Posts action.
Multiple author field values can be displayed on a single element.
For example, let’s say we have a link and want to display author’s name as its label and link it to the archive of author’s posts:
This will display the link with author’s name that points to the archive of their posts using the PHP code:
<a href="<?php echo get_author_posts_url( false, get_the_author_meta( 'user_nicename', false ) ) ?>"><?php echo get_the_author_meta( 'display_name', false ) ?></a>
Use “Add field” button to add additional author fields.
Each field has the following settings:
Selecting which field to display
Field id can be one of predefined fields, like name, or custom author field.
Like posts, authors (or users) can also have custom fields. The best way to define and edit such fields is by using Advanced Custom Fields plugin.
Selecting the custom field option will prompt us for the custom field name, with the option to use ACF for fetching the field value.
Remember, that selecting the ACF option requires the ACF plugin to be activated. Otherwise we might get a PHP run-time error.
Using the field value
Next, we decide where on the element we want to show the field value:
Content will display the field value in the inner content of the element.
Image will set the URL of the image to the src attribute of the element. This requires that the element with Author Field action is an <img> image and that the field stores an image, either as url or as id.
Background image sets the image stored in the field as element’s background using the inline style attribute. The field must contain an image, either as url or as id.
Using either of the two image options gives us the chance to select the image size we want to show.
Link sets the URL stored in the field to the href attribute of the element.
Style sets the selected inline style property, for example background color.
Attribute assigned the field value to the selected attribute.
Working with author images
WordPress supports adding author’s avatars, but that is quite limiting in terms of the size of image we can use, and even requires a plugin if we want to upload a photo without using Gravatar service.
Using ACF image fields is much friendlier solution.
For example, we can add the “author_image” image field to users and then display it with Post Author action, added on an <img> element.
In Custom Fields settings page in WordPress admin panel we create a Field group with the Author image field and assign it to Users:
We can then set the Author image field when editing the user:
And display the image with Post Author action:
Here’s how it looks on the site:
The full PHP code for both author link and image is:
<div class="author"> <p><?php _e( 'Check out my other amazing articles.', 'simple' ); ?></p> <a href="<?php echo get_author_posts_url( false, get_the_author_meta( 'user_nicename', false ) ) ?>"><?php echo get_the_author_meta( 'display_name', false ) ?></a> <img src="<?php echo PG_Image::getUrl( get_field( 'author_image', 'user_'.get_the_author_meta( 'ID', false )), 'medium' ) ?>"> </div>
To customize how this action works, click on the icon next to the action name to change it into regular WordPress actions.