Site logo

[Support request] Custom meta image

Home Forums Support [Support request] Custom meta image

Home Forums Support Custom meta image

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2257789
    Harpreet Kumar

    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?

    #2258173
    Ying
    Staff
    Customer Support

    Hi there,

    How many authors are there on your website?

    And where do you want the author’s image to show?

    #2258297
    Harpreet Kumar

    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

    #2258358
    Fernando
    Customer Support

    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!

    #2258372
    Harpreet Kumar

    Thanks, I know that way!

    But I don’t want to use Block Element. Instead, I want use custom image on default meta style.

    #2258409
    Fernando
    Customer Support

    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!

    #2258422
    Harpreet Kumar

    I tried. But nothing worked!

    #2258429
    Fernando
    Customer Support

    May I know how you’re adding the Author meta field specifically?

    Hope to hear from you soon.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.