Archived topic
Custom meta image
7 replies · Started by Harpreet Kumar on June 19, 2022
Hi,
I would like to load custom image for AUTHOR META from my WordPress media library (for my blog wpthemechecker.com) instead of Gravatar image.
How can I do that?
Hi there,
How many authors are there on your website?
And where do you want the author's image to show?
Only one author (myself) is available on website.
I would like to use a custom image under "meta" from my media library as an author. Respective screenshot has been linked at https://snipboard.io/Dhiw9M.jpg
Hi Harpreet,
The easiest way is to achieve as such is to use a Block Element - Post Meta Template Block to have full control of the layout of you Post meta.
This will allow you to add any image from your Media Library.
Here’s an article you may refer to with regards to this: https://docs.generatepress.com/article/block-element-post-meta-template/
Hope this helps!
Thanks, I know that way!
But I don't want to use Block Element. Instead, I want use custom image on default meta style.
I see. To clarify, may we know how you’re adding the custom Author meta image specifically?
If you added a post meta field, one way to retrieve it is through a PHP like this:
add_filter( 'generate_post_author_output', 'tu_custom_author_image' );
function tu_custom_author_image( $output ) {
$my_image = get_the_author_meta('img-author', get_the_author_meta( 'ID' ));
if ( $my_image ) {
return '<img src="'. $my_image . '" class="avatar"/>' . $output;
} else {
return $output;
}
}
Kindly replace img-author with the field name of your Author meta. Then, make sure the return type of the field is URL.
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Hope this helps!
I tried. But nothing worked!
May I know how you’re adding the Author meta field specifically?
Hope to hear from you soon.