[Resolved] Avatar as the featured image

Home Forums Support [Resolved] Avatar as the featured image

Home Forums Support Avatar as the featured image

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1540519
    Rogi

    There is a way to set the post author avatar as the default featured image?

    #1541433
    Elvin
    Staff
    Customer Support

    Hi,

    I’m not sure I understand what you’re trying to do.

    Can you explain a bit more?

    To clarify: Do you mean, you want the post author avatar as the default fallback image when there’s no featured image assigned to a post?

    Or do you mean, you want the post author avatar to be the featured image of posts/pages, regardless if there’s an image assigned?

    A wise man once said:
    "Have you cleared your cache?"

    #1541482
    Rogi

    Hi Elvin.

    I want the post author avatar to be the featured image of posts/pages, regardless if there’s an image assigned.

    Thanks.

    #1541597
    Elvin
    Staff
    Customer Support

    You can try adding this PHP snippet.

    add_filter( 'generate_featured_image_output', function(){
        return sprintf(
    		'<div class="post-image">
    			%3$s
    			<a href="%1$s"><img class="author-image" src="%2$s"></a>
    		</div>',
    					esc_url( get_permalink() ),
    					lh_page_hero_gravatar(),
    					apply_filters( 'generate_inside_featured_image_output', '' )
    				);
    	
    });
    
    function lh_page_hero_gravatar() {
        global $post;
        $author_id = $post->post_author;
        return get_avatar_url( $author_id,['size' => '400'] ); 
    }

    Here’s how to add PHP – https://docs.generatepress.com/article/adding-php/

    You can adjust the size by changing the 400 to a value of your preference.

    A wise man once said:
    "Have you cleared your cache?"

    #1542108
    Rogi

    Elvin,

    There was an error with the code.

    Please see

    #1542150
    David
    Staff
    Customer Support

    Hi there,

    in the code Elvin provided you will see two instances of:

    lh_page_hero_gravatar

    Change both of them to something unique eg.

    igor_page_hero_gravatar

    #1562423
    Rogi

    Thank you guys.

    #1564718
    Elvin
    Staff
    Customer Support

    Thank you guys.

    Glad to be of any help. No problem. 🙂

    A wise man once said:
    "Have you cleared your cache?"

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